HTML Attributes
HTML Attributes
An attribute is used to define the characteristics of an HTML element and is placed inside
the element's opening tag. All attributes are made up of two parts: a name and a value:
The name is the property you want to set. For example, the paragraph <p> element in the
example carries an attribute whose name is align, which you can use to indicate the
alignment of paragraph on the page.
The value is what you want the value of the property to be set and always put within
quotations. The below example shows three possible values of align attribute: left, center
and right.
Names of attributes and their values are not case-sensitive.
For example, BODY Tag, <body> carries many attributes such as bgcolor,
background that you can implement for indicating the back color of your webpage,
or give a specific image or background texture to your page, respectively.
Example:-bgcolor(attribute)
<!DOCTYPE html>
<html>
<body bgcolor=“red">
</body>
</html>
Example:-align(attribute)
<!DOCTYPE html>
<html>
<head>
<title>Align Attribute Example</title>
</head>
<body>
<p align="left">This is left aligned</p>
<p align="center">This is center aligned</p>
<p align="right">This is right aligned</p>
</body>
</html>
Example:-bdo(tag) & dir(attribute)
• The <bdo>...</bdo> element stands for Bi-Directional Override and
it is used to override the current text direction.
Example:-
<!DOCTYPE html>
<html>
<head>
<title>Text Direction Example</title>
</head>
<body>
<p>This text will go left to right.</p>
<p><bdo dir="rtl">This text will go right to left.</bdo></p>
</body>
</html>
Hyper link
• The <a> tag defines a hyperlink. which is used
to link from one page to another.
• The href attribute specifies the URL of the
page the link goes to:
• Syntax: <a href="url">link text</a>
• Example
<a href="https://lpu.in/">click here</a>
a tag & href attribute
Eample:-
<!DOCTYPE html>
<html>
<body>
<h1>Hi Everyone......</h1>
</body>
</html>
Link to an Email Address
• Use mailto: inside the href attribute to create
a link that opens the user's email program (to
let them send a new email):
• Example
• <a href="mailto:[email protected]">Se
nd email</a>
Email Example
<!DOCTYPE html>
<html>
<body>
<p>To know any information:</p>
<p><a href="mailto:[email protected]">Send
email</a></p>
</body>
</html>
The target Attribute
</body>
</html>
img tag and src attribute
</body>
</html>
Use an Image as a Link
Example:-
<!DOCTYPE html>
<html>
<body>
<h2>Image as a Link</h2>
<p>The image below is a link. Try to click on it.</p>
<a href="https://www.google.com/"><img src="C:\Users\ADMIN\
Desktop\CSE326\image1.jpg" alt="Error in opening the file"
style="width:42px;height:42px;"></a>
</body>
</html>
The lang Attribute
• You should always include the lang attribute inside
the <html> tag, to declare the language of the Web page.
• This is meant to assist search engines and browsers.
Example:-
<!DOCTYPE html>
<html lang="en">
<body>
...
</body>
</html>
lang attribute continue...
• Country codes can also be added to the language
code in the lang attribute. So, the first two characters
define the language of the HTML page, and the last
two characters define the country.
Example:-
<!DOCTYPE html>
<html lang="en-US">
<body>
...
</body>
</html>
Core Attributes