HTML name Attribute

❮ HTML Attributes

Example

<form action="action3.html" method="get">
	Click the button.
	<button name="subject" type="submit" value="HTML">HTML</button>
	<button name="subject" type="submit" value="CSS">CSS</button>
	<button name="subject" type="submit" value="JavaScript">JavaScript</button>
</form>

Meaning

The name attribute is used to define a name for the element so that it can be scripted by older browsers or used to provide a name for submit buttons when a page has more than one. The id attribute is preferred for scripting purposes.

Note: Unlimited number of <button> elements can share the same name.




Standard Syntax

<element name="name">



Browser Support




Status




Applies to:

The name attribute can be used on the following element:

Element Attribute
<button> name
<fieldset> name
<form> name
<iframe> name
<input> name
<map> name
<meta> name
<object> name
<output> name
<param> name
<select> name
<textarea> name






Attribute Values

Value Description
name The name of the elements.



More Examples

<fieldset> Example

<form action="elements/action3.html" method="get">
	<fieldset name="userinfo">
		<legend>User Info:</legend>
		<label for="fname">First name:</label>
		<input type="text" id="fname" name="fname">
	</fieldset>
	<br>
	<button type="button" onclick="form.userinfo.style.backgroundColor='tomato'"> Change background color of fieldset</button>
	<input type="submit" value="submit">
</form>



<form> Example

<form name="myForm" action="action.html" method="get">
	<label for="fname">First name:</label>
	<input type="text" id="fname" name="fname"><br>
	<label for="lname">Last name:</label>
	<input type="text" id="lname" name="lname"><br>
	<input type="submit" value="Submit">
</form>



<iframe> Example

<iframe src="demo/demo.html" name="iframe_demo">
Your browser does not support frame element.
</iframe>
<a href="demo/demo2.html" target="iframe_demo">Demo 2 HTML page.</a>



<input> Example

<form action="action.php">
	<label for="fname">First name:</label>
	<input type="text" id="fname" name="fname"><br><br>
	<label for="lname">Last name:</label>
	<input type="text" id="lname" name="lname"><br><br>
	<input type="submit" value="Submit">
</form>



<map> Example

<img src="demo/desk.jpg" usemap="#image-map">

<map name="image-map">
    <area target="_blank" alt="Mobile" title="Mobil" href="demo/mobile.png" coords="174,432,285,626" shape="rect">
    <area target="_blank" alt="computer" title="computer" href="demo/computer.png" coords="409,369,856,657" shape="rect">
    <area target="_blank" alt="clock" title="clock" href="demo/clock.png" coords="1158,203,58" shape="circle">
</map>



<meta> Example

<head>
	<meta name="language" content="EN">
	<meta name="description" content="add up to 160 characters">
	<meta name="keywords" content="your, keywords">
	<meta name="robots" content="index, follow">
	<meta name="copyright"content="company">
	<meta name="author" content="John Doe, [email protected]">
	<meta name="distribution" content="Global">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>



<object> Example

<object name="object1" data="demo/image.jpg" width="300" height="150"></object>



<output> Example

<form oninput="result.value=parseInt(a.value)+parseInt(b.value)">
	<input type="range" id="b" name="b" value="50" /> +
	<input type="number" id="a" name="a" value="10" /> =
	<output name="result" for="a b">50</output>
</form>



<param> Example

<object data="demo/video.mp4">
	<param name="videplay" value="true">
</object>



<select> Example

<label for="lang">Choose your option:</label>

<select name="language" id="lang">
	<option value="HTML">HTML</option>
	<option value="CSS">CSS</option>
	<option value="JavaScript">JavaScript</option>
</select>



<textarea> Example

Example

<form action="action.php">
	<label for="demo">textarea demo:</label>
	<textarea id="demo" name="textareaText">Hello world!</textarea>
	<br><br>
	<input type="submit" value="Submit">
</form>
❮ HTML Attributes