Skip to content

HTML attributes are properties of tags that provide additional information about HTML elements. We can use them to modify the behaviour of HTML elements.

Each tag or element can have attributes which define the behaviour of that element. We can use attributes to create dynamic and engaging web pages.

The syntax of an HTML attribute consists of the attribute name, followed by an equal sign (=), and the attribute value, enclosed in either single or double quotation marks. The general syntax for an attribute is as:

attribute_name = "attribute_value"

In the above syntax, attribute_name is the name of attribute and attribute_value is the value of an attribute. The name of attributes and values are case sensitive. So, W3C recommends it they should be written in lowercase only.

Syntax of HTML Attributes in Element


We always place attributes after the element name, separated by a space. The general syntax to place an attribute with its value within an empty element is as:

<element attribute_name="value">

Example 1:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
     <hr color = "red">
</body>
</html>

When you will run this code, it will show a red horizontal line on the web browser. The general syntax to place an attribute with its value within a non-empty element is as:

<element attribute_name="value">Content</element>

[adinserter block=”5″]
In non-empty element, attributes go in the opening tag only. We cannot put them within the closing tag.

Example 2:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
     <h1 style = "color: red">Heading 1</h1>
</body>
</html>

When you will run this code, you will get the following output on the web browser.

HTML attributesWe can also put more than one attribute in an element in any order. Just keep them separated by spaces. The general syntax is as:

<element attribute1 = "value" attribute2 = "value">

Look at the below figure where an img element with two attributes.

An img element with two HTML attributes

Key points of HTML Attributes:


There are several important points about HTML attributes you should keep in mind while working with attributes.

(1) We can put attributes after the element name in the opening tag only, never in the closing tag.
[adinserter block=”2″]
(2) As per need, we can apply several attributes to an element, separated by spaces in the opening tag. Their order is not important.

(3) Most HTML attributes take values, which follow an equal sign (=). Some attribute values take a single descriptive word.

(4) An attribute’s value can comprise a word, a string of text, a number, a URL, or a measurement, depending on the purpose of the attribute. You’ll see examples of all of these in the further HTML tutorial.

(5) Enclosing attribute values in double quotes is a strong convention, but quotation marks are not requisite in HTML5. We may omit them.

(6) HTML allows us to enclose attribute values either in single or double quotation marks. Both are acceptable as long as the opening and closing marks match. Note that quotation marks in HTML files must be straight (“), not curly (”).For example:

<a href="https://www.scientecheasy.com">A link to HTML</a>
<a href='https://www.scientecheasy.com'>A link to HTML</a>

In HTML5, we can also omit the use of quotation marks around attribute values. For example:

<a href=https://www.scientecheasy.com>A link to HTML</a>

(7) We cannot make up an attribute for an element because HTML5 specification has already defined the attribute names and values for each element.

Types of HTML Attributes


There are mainly three types of HTML attributes. They are as:

(1) Global attributes: We can use these attributes with any HTML element. They provide a general-purpose way to add additional information to an element. Some commonly used global attributes are class, id, style, and title.

(2) Event attributes: We use these attributes to define how an element responds to user actions, such as clicks or mouse movements. Some commonly used event attributes are onclick, onmouseover, and onmouseout.

(3) Element-specific attributes: These attributes are unique for specific HTML elements that provide additional customization options for elements. For example, we use the src attribute to specify the URL of an image in the img element. Some commonly used element-specific attributes are src, href, and type.

You will learn all attributes in HTML with the help of examples in the further tutorial one by one.

Guidelines for using HTML Attributes


When dealing with attributes in HTML, it is essential to follow the guidelines that make your web pages both accessible and SEO-friendly. Some important guidelines that you should keep in mind:

SEO Considerations for HTML Attributes


HTML attributes can affect your website’s search engine optimization (SEO). Here are some important things you should keep in mind:

Common Mistakes to Avoid While Using Attributes


While using HTML attributes, there are some common mistakes you should avoid. They are a few as:


In this tutorial, you have learned about HTML attributes that provide us a powerful tool for customizing and controlling the behavior of a web page. Hope that you will have understood all the basic points of attributes in HTML with examples.
Thanks for reading!!!

⇐ Prev Next ⇒

玻璃钢生产厂家昆明市玻璃钢花盆价格思明园林玻璃钢雕塑价格和田气球商场美陈装饰服务热线新乡卡通玻璃钢雕塑哪家好玛雅玻璃钢雕塑吉林玻璃钢仿铜雕塑定制动漫玻璃钢雕塑制作厂家北京玻璃钢雕塑翻制厂东莞玻璃钢农耕人物雕塑深圳季节性商场美陈哪家好赣州仿铜西式玻璃钢雕塑张掖市玻璃钢雕塑定制南湖玻璃钢雕塑厂家玉如意玻璃钢雕塑张掖玻璃钢植物雕塑哪家好生产玻璃钢雕塑厂家哪家好皋兰玻璃钢雕塑设计组合式玻璃钢雕塑摆件价钱佛像校园玻璃钢雕塑定制厂家连云港玻璃钢仿真水果雕塑价格佛山玻璃钢防铜动物雕塑装饰商场美陈有哪些辽宁商场创意商业美陈经验邯郸彩绘玻璃钢雕塑广州企业形象雕塑玻璃钢玻璃钢艺术雕塑品南京浦口商场美陈浦口百货商场美陈红河玻璃钢雕塑定做福州玻璃钢雕塑厂家香港通过《维护国家安全条例》两大学生合买彩票中奖一人不认账让美丽中国“从细节出发”19岁小伙救下5人后溺亡 多方发声单亲妈妈陷入热恋 14岁儿子报警汪小菲曝离婚始末遭遇山火的松茸之乡雅江山火三名扑火人员牺牲系谣言何赛飞追着代拍打萧美琴窜访捷克 外交部回应卫健委通报少年有偿捐血浆16次猝死手机成瘾是影响睡眠质量重要因素高校汽车撞人致3死16伤 司机系学生315晚会后胖东来又人满为患了小米汽车超级工厂正式揭幕中国拥有亿元资产的家庭达13.3万户周杰伦一审败诉网易男孩8年未见母亲被告知被遗忘许家印被限制高消费饲养员用铁锨驱打大熊猫被辞退男子被猫抓伤后确诊“猫抓病”特朗普无法缴纳4.54亿美元罚金倪萍分享减重40斤方法联合利华开始重组张家界的山上“长”满了韩国人?张立群任西安交通大学校长杨倩无缘巴黎奥运“重生之我在北大当嫡校长”黑马情侣提车了专访95后高颜值猪保姆考生莫言也上北大硕士复试名单了网友洛杉矶偶遇贾玲专家建议不必谈骨泥色变沉迷短剧的人就像掉进了杀猪盘奥巴马现身唐宁街 黑色着装引猜测七年后宇文玥被薅头发捞上岸事业单位女子向同事水杯投不明物质凯特王妃现身!外出购物视频曝光河南驻马店通报西平中学跳楼事件王树国卸任西安交大校长 师生送别恒大被罚41.75亿到底怎么缴男子被流浪猫绊倒 投喂者赔24万房客欠租失踪 房东直发愁西双版纳热带植物园回应蜉蝣大爆发钱人豪晒法院裁定实锤抄袭外国人感慨凌晨的中国很安全胖东来员工每周单休无小长假白宫:哈马斯三号人物被杀测试车高速逃费 小米:已补缴老人退休金被冒领16年 金额超20万

玻璃钢生产厂家 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化