HTML Exam 5: Modern HTML5 Features (10 Challenges)

HTML Exam 5: Mastery and Modern Features

Test your knowledge of modern HTML5 elements, APIs, and performance optimization techniques.

Exercise 1 Dialog Windows (Dialog Element)

Use the <dialog> element to create a simple modal window with a “Hello” message and a close button. Give it the id “myModal”.

Solution
<dialog id="myModal">
    <p>Hello there!</p>
    <form method="dialog">
        <button>Close</button>
    </form>
</dialog>
Exercise 2 Drag and Drop

Make an image (`img`) draggable using the `draggable` attribute.

Solution
<img src="image.jpg" draggable="true" alt="Draggable image">
Exercise 3 Output Element

Create a form with two range inputs and an <output> element that displays their sum. (HTML only.)

Solution
<form oninput="result.value = parseInt(a.value) + parseInt(b.value)">
    <input type="range" id="a" value="50"> +
    <input type="range" id="b" value="50"> =
    <output name="result" for="a b">100</output>
</form>
Exercise 4 Structured Data (Microdata)

Use Microdata attributes (itemscope, itemtype, itemprop) to define a Person named “Ali” with the job title “Developer”.

Solution
<div itemscope itemtype="https://schema.org/Person">
    <span itemprop="name">Ali</span>
    <span itemprop="jobTitle">Developer</span>
</div>
Exercise 5 Preloading

Write a <link> tag to preload the font file “font.woff2” to improve performance.

Solution
<link rel="preload" href="font.woff2" as="font" type="font/woff2" crossorigin>
Exercise 6 Hidden Attribute

Use the global `hidden` attribute to hide a <p> element with the text “Coming soon” without using CSS.

Solution
<p hidden>Coming soon</p>
Exercise 7 Bi-directional Text

You have a sentence that mixes languages and want to isolate the direction of an English username. Use the appropriate tag (<bdi>).

Solution
<p>User <bdi>User123</bdi> won the game.</p>
Exercise 8 Spellcheck and Translation

1. Disable spellcheck for a text input field.
2. Prevent translation of a company name using `translate=\"no\"` inside a paragraph.

Solution
<input type="text" spellcheck="false">

<p>Welcome to <span translate="no">Google</span>.</p>
Exercise 9 Content Security Policy (CSP)

Write a meta tag that defines a Content Security Policy allowing scripts only from the same origin (`self`).

Solution
<meta http-equiv="Content-Security-Policy" content="script-src 'self'">
Exercise 10 Responsive Images (srcset & sizes)

Use `srcset` and `sizes` on an `img` tag to provide different image versions based on screen width (e.g., a small image up to 600px and a larger one above that).

Solution
<img src="small.jpg" 
     srcset="small.jpg 500w, medium.jpg 1000w, large.jpg 1500w" 
     sizes="(max-width: 600px) 500px, 100vw" 
     alt="Responsive image">
Smart Editor

Write code and see the result instantly

Try it free