HTML for Web Development

0% completed

Previous
Next
Reference to Common HTML Attributes

In this lesson, we will explore the most commonly used HTML attributes and their purposes. Below is a reference table containing common HTML attributes, their descriptions, and examples to help you understand their usage.

AttributeDescriptionExample
idSpecifies a unique identifier for an element.<div id="main-container">This is a container</div>
classSpecifies one or more class names for an element, used for styling.<p class="highlight">This is a paragraph</p>
styleAdds inline CSS to an element.<div style="color: red; background-color: yellow;">Styled Content</div>
titleAdds a tooltip text that appears when the user hovers over the element.<span title="Tooltip text">Hover over me</span>
srcSpecifies the URL of the source for an image, video, or iframe.<img src="logo.png" alt="DesignGurus Logo" />
altProvides alternative text for an image if it cannot be displayed.<img src="image.jpg" alt="Alternative Text" />
hrefSpecifies the URL of the page the link goes to.<a href="https://designgurus.io">Visit DesignGurus</a>
targetSpecifies where to open the linked document (_self, _blank, etc.).<a href="https://designgurus.io" target="_blank">Open in New Tab</a>
typeSpecifies the type of input element (e.g., text, password, checkbox).<input type="text" name="username" />
valueSpecifies the initial value of an input field.<input type="text" value="Default Text" />
nameSpecifies the name of an input element for form data submission.<input type="text" name="username" />
placeholderProvides a short hint describing the expected value in an input field.<input type="text" placeholder="Enter your name" />
maxlengthSpecifies the maximum number of characters allowed in an input field.<input type="text" maxlength="20" />
checkedSpecifies that an input element (checkbox or radio) should be preselected.<input type="checkbox" checked />
readonlySpecifies that an input field is read-only.<input type="text" value="Read-only text" readonly />
disabledDisables an input element, making it unclickable.<button disabled>Click Me</button>
requiredSpecifies that an input field must be filled out before submitting a form.<input type="text" required />
min and maxSpecifies the minimum and maximum values for numeric input fields.<input type="number" min="1" max="10" />
stepSpecifies the interval for numeric input fields.<input type="number" step="2" />
cols and rowsSpecifies the visible width and height of a <textarea> element.<textarea cols="30" rows="5">Default Text</textarea>
multipleAllows multiple values to be selected in a drop-down list or file input.<select multiple><option>Option 1</option></select>
autofocusSpecifies that an input field should automatically focus when the page loads.<input type="text" autofocus />
actionSpecifies the URL to send form data when a form is submitted.<form action="/submit-form"><input type="text" /></form>
methodSpecifies the HTTP method to use when submitting form data (GET or POST).<form method="POST"><input type="text" /></form>
forSpecifies which form element a <label> is bound to.<label for="username">User Name:</label><input type="text" id="username" />
srcsetSpecifies multiple image resources for responsive images.<img src="small.jpg" srcset="large.jpg 1024w" alt="Responsive Image" />
altProvides alternative text for an image.<img src="logo.png" alt="Company Logo" />
langSpecifies the language of the document or element.<html lang="en">
charsetSpecifies the character encoding for the document.<meta charset="UTF-8" />
contentProvides metadata values for the <meta> element.<meta name="description" content="Learn HTML with DesignGurus">
relSpecifies the relationship between the current document and linked resource.<link rel="stylesheet" href="style.css" />
asyncLoads a script asynchronously.<script src="script.js" async></script>
deferDefers loading of a script until after the HTML document has been parsed.<script src="script.js" defer></script>
controlsAdds play, pause, and volume controls to media elements.<audio controls><source src="audio.mp3" type="audio/mpeg"></audio>
loopSpecifies that the media should start over again when it is finished.<video src="video.mp4" loop></video>
autoplaySpecifies that the media should start playing as soon as it is ready.<audio src="song.mp3" autoplay></audio>
mutedSpecifies that the media should be muted by default.<video src="video.mp4" muted></video>
draggableSpecifies whether an element is draggable or not.<div draggable="true">Drag Me</div>

.....

.....

.....

Like the course? Get enrolled and start learning!
Previous
Next