Which snippet would correctly set the page background color to purple?

Learn web design with our comprehensive test guide. Improve your skills with flashcards and multiple choice questions. Each question includes hints and explanations. Get ready to ace your exam!

Multiple Choice

Which snippet would correctly set the page background color to purple?

Explanation:
Setting the page background color is done with CSS by applying the background-color property to the body element. The inline style on the body tag directly assigns background-color: purple, so the entire page background becomes purple as soon as the page loads. Inline styles are applied immediately and have high specificity, making this a simple, reliable way to color the page background. Using the older bgcolor attribute on the body isn’t standard in HTML5 and isn’t recommended, even if it might work in some browsers. A separate style block with a CSS rule can also work, but it needs to be placed correctly in the document (for example, inside a style tag in the head) and is not as immediately explicit as an inline style on the body. Coloring a div would only affect that particular element, not the whole page background.

Setting the page background color is done with CSS by applying the background-color property to the body element. The inline style on the body tag directly assigns background-color: purple, so the entire page background becomes purple as soon as the page loads. Inline styles are applied immediately and have high specificity, making this a simple, reliable way to color the page background.

Using the older bgcolor attribute on the body isn’t standard in HTML5 and isn’t recommended, even if it might work in some browsers. A separate style block with a CSS rule can also work, but it needs to be placed correctly in the document (for example, inside a style tag in the head) and is not as immediately explicit as an inline style on the body. Coloring a div would only affect that particular element, not the whole page background.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy