Question: What is the purpose of semantic HTML elements?
|
Answer: Semantic HTML elements provide meaning to the content they enclose, making it easier for developers to understand
the structure and purpose of a web page.
Semantic elements like <header>, <footer>, <nav>, <article>, and <section> improve accessibility, SEO, and maintainability of the code.
|
Question: How do you embed a video in an HTML document?
|
Answer: You can embed a video in an HTML document using the <video> element. For example:
<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
Here the <video> element has the 'src' attribute specifying the URL of the video file,
and 'type' attribute for the MIME type of the video. And the 'controls' attribute adds playback controls to the video player.
|
Question: How do you create a hyperlink that opens in a new tab/window on browser?
|
Answer: To create a hyperlink that opens in a new tab/window, we need to add the target="_blank" attribute
to the <a> tag. For example:
<a href="https://www.example.com" target="_blank">Visit Example</a>
|
Question: What is the purpose of the 'role' attribute in HTML?
|
Answer: The 'role' attribute is used to define the purpose or role of an element in the document structure,
especially for elements that do not convey their semantic meaning clearly.
It is primarily used to improve accessibility by providing additional information to assistive technologies like screen readers.
For example, '<div role="navigation">' specifies that the '<div>' element serves as a navigation menu,
helping screen readers navigate the page more effectively.
|
Question: What is the purpose of the 'autocomplete' attribute in HTML form elements?
|
Answer: The autocomplete attribute is used to control whether browsers should automatically complete
input fields based on the user's previous input or saved values. It can take values such as 'on' (enable autocomplete),
'off' (disable autocomplete), or specific values like 'name', 'email', 'tel', etc.,
to enable autocomplete for specific types of data.
For example, '<input type="text" autocomplete="off">' disables autocomplete for a text input field.
|
Question: How can you implement client-side validation using HTML5 attributes?
|
Answer: HTML5 introduced built-in form validation features that allow you to validate user input directly
in the browser without using JavaScript. You can use attributes like 'required', 'type', 'min',
'max', 'pattern', etc., to specify validation rules for form fields.
For example, '<input type="email" required>' ensures that the input field must contain a valid email address,
and it is required to be filled out before submitting the form.
|
Question: What is the purpose of the '<table>' element in HTML?
|
Answer: The '<table>' element is used to create tables in HTML, which are used to display tabular data
in rows and columns. To create a basic table structure, you need to use the '<table>' element to define the table,
'<tr>' (table row) elements to define rows, '<th>' (table header) elements to define header cells,
and '<td>' (table data) elements to define data cells.
|