HTML Attributes
Html attributes are the word which are used to control the behaviour of the element.
It is used inside the opening tag.
The syntax of attribute is name = "value".
Example:
<!DOCTYPE html>
<html>
<head>
<title> Page Title </title>
</head>
<body>
<h1> This is an attribute example. </h1>
<img src="images.jpg">
</body>
</html>
<html>
<head>
<title> Page Title </title>
</head>
<body>
<h1> This is an attribute example. </h1>
<img src="images.jpg">
</body>
</html>
Run Example
The id Attribute
The id attribute provides an unique identification of the elements.
Example:
<!DOCTYPE html>
<html>
<head>
<title> Page Title </title>
</head>
<body>
<h1> This is id attribute example. </h1>
<h1 id="unique"> id attribute </h1>
</body>
</html>
<html>
<head>
<title> Page Title </title>
</head>
<body>
<h1> This is id attribute example. </h1>
<h1 id="unique"> id attribute </h1>
</body>
</html>
Run Example
The class Attribute
The class attribute provides a way to classify similar elements.
Example:
<!DOCTYPE html>
<html>
<head>
<title> Page Title </title>
</head>
<body>
<h1> This is class attribute example. </h1>
<h1 class="similar"> class attribute </h1>
</body>
</html>
<html>
<head>
<title> Page Title </title>
</head>
<body>
<h1> This is class attribute example. </h1>
<h1 class="similar"> class attribute </h1>
</body>
</html>
Run Example
The href Attribute
The href attribute provides a way to connect with the CSS, JavaScript and other pages.
Example:
<!DOCTYPE html>
<html>
<head>
<title> Page Title </title>
</head>
<body>
<h1> This is href attribute example. </h1>
<a href="www.google.com"> This is a link </a>
</body>
</html>
<html>
<head>
<title> Page Title </title>
</head>
<body>
<h1> This is href attribute example. </h1>
<a href="www.google.com"> This is a link </a>
</body>
</html>
Run Example
The src Attribute
The src attribute is used specially for using an image into the website.
Example:
<!DOCTYPE html>
<html>
<head>
<title> Page Title </title>
</head>
<body>
<h1> This is an attribute example. </h1>
<img src="images/html.jpg">
</body>
</html>
<html>
<head>
<title> Page Title </title>
</head>
<body>
<h1> This is an attribute example. </h1>
<img src="images/html.jpg">
</body>
</html>
Run Example
The alt Attribute
The alt attribute is used for an alternative text when an image can't be displayed.
Example:
<!DOCTYPE html>
<html>
<head>
<title> Page Title </title>
</head>
<body>
<h1> This is an attribute example. </h1>
<img src="images/htm.jpg" alt="This is an HTML image">
</body>
</html>
<html>
<head>
<title> Page Title </title>
</head>
<body>
<h1> This is an attribute example. </h1>
<img src="images/htm.jpg" alt="This is an HTML image">
</body>
</html>
Run Example