Bird
Raised Fist0
HTMLmarkup~20 mins

What are attributes in HTML - Practice Questions & Exercises

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Attribute Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding HTML Attributes
Which of the following best describes what an attribute in an HTML tag does?
AIt provides extra information about an element, like its ID or style.
BIt creates a new HTML element inside the tag.
CIt removes the element from the page.
DIt changes the browser's default font.
Attempts:
2 left
💡 Hint
Think about how you add details to an HTML tag to change its behavior or appearance.
📝 Syntax
intermediate
1:30remaining
Correct Attribute Syntax
Which option shows the correct way to add a class attribute to a <div> element?
HTML
<div ???>Content</div>
Aclass=container
Bclass='container'
Cclass:"container"
Dclass-container
Attempts:
2 left
💡 Hint
Attributes need an equals sign and quotes around the value.
❓ rendering
advanced
2:00remaining
Effect of the alt Attribute on Images
What will the browser display if an image has a broken link but includes an alt attribute like alt="Logo"?
HTML
<img src="broken-link.jpg" alt="Logo">
AThe browser will crash.
BNothing will show; the image area will be blank.
CThe broken image icon with no text.
DThe text 'Logo' will be shown in place of the image.
Attempts:
2 left
💡 Hint
Alt text helps when images cannot load.
❓ selector
advanced
2:00remaining
Selecting Elements by Attribute in CSS
Which CSS selector will style all <a> elements that have a title attribute?
Aa[title] { color: blue; }
Ba.title { color: blue; }
Ca#title { color: blue; }
Da(title) { color: blue; }
Attempts:
2 left
💡 Hint
Attribute selectors use square brackets.
❓ accessibility
expert
2:30remaining
Role of ARIA Attributes
What is the main purpose of ARIA attributes like aria-label in HTML?
ATo add animations to elements.
BTo change the visual style of elements.
CTo improve accessibility by providing extra information to screen readers.
DTo make elements draggable.
Attempts:
2 left
💡 Hint
ARIA helps people who use assistive technology.

Practice

(1/5)
1. What is the main purpose of attributes in HTML elements?
easy
A. To add extra information or settings to elements
B. To create new HTML elements
C. To write comments inside HTML
D. To link CSS files to the HTML

Solution

  1. Step 1: Understand what attributes do

    Attributes provide extra details or settings inside an element's opening tag.
  2. Step 2: Compare options with attribute purpose

    Only To add extra information or settings to elements correctly describes adding extra information or settings to elements.
  3. Final Answer:

    To add extra information or settings to elements -> Option A
  4. Quick Check:

    Attributes add details = B [OK]
Hint: Attributes add info inside tags, not create elements [OK]
Common Mistakes:
  • Confusing attributes with creating elements
  • Thinking attributes are for comments
  • Mixing attributes with linking CSS
2. Which of the following is the correct way to add an attribute to an HTML element?
easy
A.
Content
B.
Content
C.
Content
D.

Solution

  1. Step 1: Check attribute syntax rules

    Attributes go inside the opening tag with name="value" or name='value'.
  2. Step 2: Identify correct syntax among options

    <div id='main'>Content</div> uses correct syntax: <div id='main'>. Others have syntax errors.
  3. Final Answer:

    <div id='main'>Content</div> -> Option C
  4. Quick Check:

    Correct attribute syntax = C [OK]
Hint: Attributes need name='value' inside opening tag [OK]
Common Mistakes:
  • Using dashes instead of equals sign
  • Putting quotes around attribute name
  • Missing quotes around attribute value
3. What will the following HTML code display in the browser?
<img src='flower.jpg' alt='A red flower'>
medium
A. An image of a red flower with alt text shown if image fails
B. Only the text 'A red flower' will show
C. Nothing will show because img needs a closing tag
D. An error message will appear in the browser

Solution

  1. Step 1: Understand img tag and attributes

    The img tag shows an image from src attribute; alt text shows if image can't load.
  2. Step 2: Predict browser behavior

    Browser displays the image if available; alt text only appears if image fails to load.
  3. Final Answer:

    An image of a red flower with alt text shown if image fails -> Option A
  4. Quick Check:

    img src shows image, alt is fallback text = A [OK]
Hint: img shows image; alt text is fallback description [OK]
Common Mistakes:
  • Thinking alt text always shows
  • Believing img needs closing tag
  • Expecting error for missing closing tag
4. Find the error in this HTML snippet:
<a href='page.html' target='_blank>Visit page</a>
medium
A. href attribute is misspelled
B. Missing closing quote for target attribute value
C. Anchor tag cannot have attributes
D. The link text is missing

Solution

  1. Step 1: Check attribute syntax carefully

    The target attribute value '_blank' is missing the closing quote before the >.
  2. Step 2: Confirm other parts are correct

    href is spelled correctly, anchor tags can have attributes, and link text is present.
  3. Final Answer:

    Missing closing quote for target attribute value -> Option B
  4. Quick Check:

    Attribute values need quotes closed = A [OK]
Hint: Always close quotes around attribute values [OK]
Common Mistakes:
  • Ignoring missing quotes
  • Thinking attributes can't have quotes
  • Confusing attribute names
5. You want to make a button that is disabled and has a tooltip saying 'Not clickable'. Which attributes should you add to the button element?
hard
A. Click me
B. Click me
C. Click me
D. Click me

Solution

  1. Step 1: Identify correct attribute for disabling button

    The 'disabled' attribute disables the button when present without value or with value 'disabled'.
  2. Step 2: Identify correct attribute for tooltip

    The 'title' attribute shows a tooltip on hover with the given text.
  3. Final Answer:

    <button disabled title='Not clickable'>Click me</button> -> Option D
  4. Quick Check:

    disabled disables, title shows tooltip = D [OK]
Hint: Use 'disabled' and 'title' attributes for button and tooltip [OK]
Common Mistakes:
  • Using wrong attribute names like 'disable' or 'tooltip'
  • Setting disabled='false' which does not disable
  • Confusing alt with title attribute
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard