HTML Attributes
An attribute is an extra descriptive piece of information about an HTML element. Attributes can specify how we want our element to look or function. Take a look at an example attribute below:
<p align="center"></p>
The attribute above align="center"
will tell our element that we want the text inside of the paragraph element to align center. Take a look at the example code below:
Paragraph Align Attribute
So, from the example above align
is our attribute and center
is the attribute value.
There are a ton of attributes that we can use for our HTML elements. Some attributes can only be used by specific elements, but there are some attributes that can be used by all elements. One of the most popular attributes that can be used by all elements is the style
attribute.
style Attribute
The style attribute will add inline styles (CSS) to your element. You will learn a lot more about adding style to your elements when you cover the CSS section.
Below you will find an example of each of the most commonly used HTML attributes:
title Attribute
<p title="I'm a tooltip">I'm a paragraph</p>
The title attribute will specify some more information about the element. This is commonly used for SEO purposes and helpful tooltips for the user.
alt attribute
<img alt="descriptive information about this image">
The alt attribute is used as alternate text for an image when the image cannot be displayed.
src attribute
<img src="link_to_image.jpg">
The src attribute will specify the location or the URL of an image.
width and height attributes
<img src="link_to_image.jpg" width="300" height="200">
The width and height attributes will specify what size to display the image.
href attribute
<a href="http://www.google.com">Visit Google</a>
The href attribute is used to display the URL that you want the user to go to when the click on the link for the link <a>
tag.
There are many more attributes that can be used in your HTML elements. Above are some of the most commonly used attributes and we will be covering many more in the next few sections.
Next up, let's move on to talking about HTML Paragraphs.