Interview Questions

HTML Coding Questions and Answers

  1. Write HTML code to create a simple web page with a heading and a paragraph.

    Use the following code:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Simple Page</title>
    </head>
    <body>
        <h1>Welcome to My Web Page</h1>
        <p>This is a simple paragraph on the page.</p>
    </body>
    </html>
                        
  2. Write HTML code to create a form with a text input, radio buttons, and a submit button.

    Use the following code:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Form Example</title>
    </head>
    <body>
        <form action="/submit" method="post">
            <label for="name">Name:</label>
            <input type="text" id="name" name="name">
            <br>
            <label>Gender:</label>
            <input type="radio" id="male" name="gender" value="male">
            <label for="male">Male</label>
            <input type="radio" id="female" name="gender" value="female">
            <label for="female">Female</label>
            <br>
            <button type="submit">Submit</button>
        </form>
    </body>
    </html>
                        
  3. Write HTML code to create a table with three columns and two rows.

    Use the following code:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Table Example</title>
    </head>
    <body>
        <table border="1">
            <tr>
                <th>Header 1</th>
                <th>Header 2</th>
                <th>Header 3</th>
            </tr>
            <tr>
                <td>Row 1, Cell 1</td>
                <td>Row 1, Cell 2</td>
                <td>Row 1, Cell 3</td>
            </tr>
            <tr>
                <td>Row 2, Cell 1</td>
                <td>Row 2, Cell 2</td>
                <td>Row 2, Cell 3</td>
            </tr>
        </table>
    </body>
    </html>
                        
  4. Write HTML code to create a hyperlink that opens a new tab.

    Use the following code:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Link Example</title>
    </head>
    <body>
        <a href="https://www.example.com" target="_blank">Visit Example.com</a>
    </body>
    </html>
                        
  5. Write HTML code to create an ordered list with three items.

    Use the following code:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Ordered List Example</title>
    </head>
    <body>
        <ol>
            <li>Item 1</li>
            <li>Item 2</li>
            <li>Item 3</li>
        </ol>
    </body>
    </html>
                        
  6. Write HTML code to create an unordered list with four items.

    Use the following code:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Unordered List Example</title>
    </head>
    <body>
        <ul>
            <li>Item 1</li>
            <li>Item 2</li>
            <li>Item 3</li>
            <li>Item 4</li>
        </ul>
    </body>
    </html>
                        
  7. Write HTML code to create a form with a textarea.

    Use the following code:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Textarea Example</title>
    </head>
    <body>
        <form action="/submit" method="post">
            <label for="message">Message:</label>
            <textarea id="message" name="message"></textarea>
            <br>
            <button type="submit">Submit</button>
        </form>
    </body>
    </html>
                        
  8. Write HTML code to include an image with an alt attribute.

    Use the following code:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Image Example</title>
    </head>
    <body>
        <img src="image.jpg" alt="A descriptive text for the image">
    </body>
    </html>
                        
  9. Write HTML code to embed a YouTube video.

    Use the following code:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Video Example</title>
    </head>
    <body>
        <iframe width="560" height="315" src="https://www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allowfullscreen></iframe>
    </body>
    </html>
                        
  10. How do you create a table with a header and two rows in HTML?

    Use the following HTML code:

    Header 1 Header 2
    Row 1, Cell 1 Row 1, Cell 2
    Row 2, Cell 1 Row 2, Cell 2
  11. How do you create a form with a text input and a submit button in HTML?

    Use the following HTML code:

  12. How do you create a hyperlink that opens in a new tab in HTML?

    Use the following HTML code:

  13. How do you create a dropdown menu in HTML?

    Use the following HTML code:

    
            
  14. How do you create an ordered list with three items in HTML?

    Use the following HTML code:

    1. First Item
    2. Second Item
    3. Third Item
  15. Write HTML code to create a div with a class "box" and some text inside it.

    Use the following code:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Div Example</title>
    </head>
    <body>
        <div class="box">
            <p>This is a div with a class "box".</p>
        </div>
    </body>
    </html>
                        
  16. Write HTML code to create a header with a navigation menu.

    Use the following code:

                        
        <!DOCTYPE html>
        <html lang="en">
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>Navigation Example</title>
        </head>
        <body>
            <header>
                <nav>
                    <ul>
                        <li><a href="#home">Home</a></li>
                        <li><a href="#about">About</a></li>
                        <li><a href="#contact">Contact</a></li>
                    </ul>
                </nav>
            </header>
        </body>
        </html>
                            
                        
  17. Write HTML code to create a list of links.

    Use the following code:

        <!DOCTYPE html>
        <html lang="en">
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>Links Example</title>
        </head>
        <body>
            <ul>
                <li><a href="https://www.example1.com">Example 1</a></li>
                <li><a href="https://www.example2.com">Example 2</a></li>
                <li><a href="https://www.example3.com">Example 3</a></li>
            </ul>
        </body>
        </html>
                          
                        
  18. Write HTML code to create a section with a heading and a paragraph.

    Use the following code:

        <!DOCTYPE html>
        <html lang="en">
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>Section Example</title>
        </head>
        <body>
            <section>
                <h2>Section Heading</h2>
                <p>This is a paragraph within a section.</p>
            </section>
        </body>
        </html>
                        
  19. Write HTML code to create a div with a class and some content.

    Use the following code:

        <!DOCTYPE html>
        <html lang="en">
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>Div Example</title>
        </head>
        <body>
            <div class="my-class">
                <p>This is a div with a class and some content.</p>
            </div>
        </body>
        </html>
                            
                        
  20. Write HTML code to create an iframe embedding a video.

    Use the following code:

        <!DOCTYPE html>
        <html lang="en">
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>Iframe Example</title>
        </head>
        <body>
            <iframe width="560" height="315" src="https://www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        </body>
        </html>
                            
                        
Creative Footer for Interview Questions