HTML Attributes
HTML Attributes provide additional information about HTML elements.
HTML attributes
- All HTML element can have attributes
- Attributes provide additional information about elements
- Attribute are always specified in the start tag
- Attributes usually come in name value pairs link: name="value"
The href attribute
The < a> tag defines a hyperlink. The href attribute specifies the URL of the page the goeg to :
Example
The src attribute
The < img> tag is use to embed an image in an HTML page. The src attribute specifies the path to the image to be displayed.
Example
The are two ways to specify the URL in the src attribute
1.Absolute URL - link to an external image that is hosted on another website. Example src="https://codezara.com/image/codezara-image-1.webp"
Note:External images might be under copyright. if you do not get premissionto use it you may be in violation of copyright laws. in addition you can not control external images it can suddenly be remove or changed
2. relative Url - links to an image that is hosted within the website here the url does not include the domain name if the url begins without a slash it will be relative to the corrent page. example src="image/codezara-image-1.webp". if the url begins with a slash it will be relative to the domain. examplesrc="image/codezara-image-1.webp".
Tips it is almost always best to use relative urls. they will not break if yoy change domain.
The width and height attributes
The < img> tag should also contain the width and height attributes which specify the width and height of the image (in pixels).