Attributes in HTML

Properties are used to add information to elements in HTML.

Properties are used to add information to elements in HTML.

Characteristics of HTML attributes

  1. All HTML elements have attributes
  2. Additional properties for the element information
  3. Attributes are usually specified in the opening tag
  4. Attributes often follow name-value pairs, such as ten = "giatri"

Href attribute

The path in HTML is determined by the tag and the path address is determined by the href. attribute href.

For example

 Quản trị mạng 

Src attribute

Images in HTML are determined by tags , , the filename of the image source is determined by the src. attribute src.

For example

  

Width and height attributes

Images in HTML also have properties that determine the size, width and height.

For example

  

The image size is determined in pixels, with a height of 200 pixels and a width of 540 pixels. There will be separate images in the following HTML for you to understand.

Alt attribute

The alt attribute specifies the alternate text used when the image cannot be displayed. The value of this attribute can be read on the screen reader. As a result, people can 'listen' to the website, for example, visually impaired people can 'listen' to HTML elements.

For example

 News sites, technology tips 

The alt attribute is also useful if the image does not exist. Eg:

 Learn HTML together 

Style properties

style attribute is used to define the style for an element, such as color, font, size .

For example

I like reading Network Administration

Lang attribute

Text language is defined from the card Language is defined by lang attribute. Language definition is very important for applications that support accessibility (such as screen readers) and search engines.








The first two letters define the language, and if you want to specify only the dialect, use the following 2 letters (US). This indicates the text used in American English.

Title attribute

The title attribute is added to the element

with the value of the attribute displayed as a comment when you drag the mouse over the text.

For example

 


Tôi đang học HTML trên Quản trị mạng.

A few other notes

Use quotation marks for values

Although HTML5 is not required to have quotation marks for attribute values, W3C encourages you to use this mark. Sometimes using quotation marks is mandatory, as in the example below, the title will not display properly without a quotation mark, because it contains spaces.

 

Should I use double quotes or single quotes?

It is possible to use single quotation marks but double quotation marks are still more common in HTML. In some cases, when right in the attribute value already contains double quotation marks, it is advisable to use a single quotation mark, and vice versa.

 

hoặc

 

Previous article: Elements in HTML

The following article: Title tags in HTML

Update 25 May 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile