Skip to content
techsnow

Introduction

HTML Attributes

Attributes give extra information about an element. They always go inside the opening tag and are written as name="value".

Syntax:

<tagname attribute="value">Content</tagname>
<a href="https://techsnow.com" target="_blank">Visit TechSnow</a>
<img src="logo.png" alt="TechSnow logo" width="120">

Common attributes

AttributeUsed onPurpose
href<a>, <link>The address a link points to.
src<img>, <script>, <video>The file to load.
alt<img>Alternative text describing an image.
idAny elementA unique name for one element.
classAny elementA reusable name for styling groups of elements.
styleAny elementInline CSS styles.
titleAny elementExtra info shown as a tooltip on hover.
lang<html>The language of the page.

Boolean attributes

Some attributes need no value. Just writing them switches the feature on.

<input type="checkbox" checked>
<button disabled>Can't click me</button>
<video src="intro.mp4" controls autoplay muted></video>