These HTML questions are not only for the interview but also for your self-assessment. So try to understand the answer instead of imitating.

How to comment in HTML?

The comment syntax in HTML is as follows:

<!-- This is an HTML comment -->

Anything within the comment symbol will be ignored by the web browser. The browser will not execute any comment. The comment in HTML or any other language is just for the developers and internal purposes. It has no meaning to web browsers.

Comment in CSS

/* This is a comment in CSS */

How to underline text in HTML?

To underline a text/word/sentence in HTML use the <u> tag. See the syntax below:

<p>You can <u>underline</u> any portion with the "u tag." Also you can use CSS for it instead. The both ways are valid.</p>

So anything within the u-tag will be underlined.

How to make bold text in HTML?

The <strong> and <b> HTML tags can make a text bold.

<p>Use either the "strong" or "b" tag to make a text bold. <strong>It is bold text using strong-tag</strong> and <b>this is bold using b-tag</b>. Try any of them.</p>

How to center HTML text?

The <center> tag was used to center text in HTML in the past. But it’s not supported in HTML5. So now you have to use CSS to center the text in HTML.

.xyz {
    text-align: center;
}

If you don’t have access to the CSS file or if you need to center the element through the HTML file, you can either write inline CSS or within a “style” tag. See both examples below:

<p style="text-align: center;">This is a center aligned text using inline CSS.</p>

<style type="text/css">
  p {text-align: center;}
</style>

How to center image in HTML

The best way to center an image is to write CSS. But if it’s indeed to use only the HTML file to center an image, you can wrap the image within a <div> and align its text to the center. That will position the image center. See the code below what I mean:

<div style="text-align: center;">
  <img src="image-name.jpg">
</div>

But it’s a better approach to not write inline CSS. To center an image in CSS, first, you have to block its display and then auto-margin both from left & right sides. Here is what I mean:

img {
    display: block;
    margin: 0 auto;
}

The margin: 0 auto means, zero margins on top & bottom, and auto margin on left & right.

You can also do anyone from the following:

img {
    display: block;
    margin-left: auto;
    margin-right: auto;
}

img {
    display: block;
    margin: auto;
    /*it will assign auto margin from four directions*/
}

img {
    display: block;
    margin: 30px auto;
    /*it will assign 30px margin on top & bottom, and auto margin on left & right */
}