Attributes 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

4 ★ | 2 Vote

May be interested

  • HTML formHTML form
    the form in html contains form elements - the element types that take input data such as filling in text fields, checkboxes, buttons, submit buttons ...
  • Style properties in HTMLStyle properties in HTML
    the style attribute specifies the style for the html element.
  • Text in HTMLText in HTML
    the element in html is used to define a paragraph of text.
  • How to Use Text Color Tags in HTMLHow to Use Text Color Tags in HTML
    this article explains how to change the font color in html documents. although the html style tag is obsolete in html5, you can use css to color content on an html page. if you use an older version of html, you can use the html text color tag as needed.
  • Format text in HTMLFormat text in HTML
    format elements in html help determine the style and importance of text.
  • Elements in HTMLElements in HTML
    the html element usually goes in pairs, including the opening tag, closing tag, and the content inside the two tags.
  • Symbol - Icon in HTMLSymbol - Icon in HTML
    html has many mathematical, technical and monetary symbols that cannot be used to write.
  • Common HTML mistakes that you should avoid for better web programmingCommon HTML mistakes that you should avoid for better web programming
    learning html is not difficult, but when running it in the browser, errors often occur. here are common html errors and how to handle them for better web development.
  • How to insert spaces in HTMLHow to insert spaces in HTML
    this tutorial explains how to insert spaces and line breaks in html. because no matter how many times you type a space, html will display a space so to insert more than one space, you will need to use the html tag.
  • Image img in HTMLImage img in HTML
    when you visit the website, you will often see images of all sizes and positions on the page. images in html web pages will help to enrich the content as well as increase the aesthetics of the page.