W3docs

css · CSS Basics

Which is the correct syntax to make all <p> elements bold?

Answers

  • p {font-weight bold}
  • p: {font-weight: bold}
  • p style='font-weight: bold'
  • p {font-weight: bold}
# Understanding CSS Syntax: Making Paragraph Elements Bold When working with CSS, it's crucial to get the syntax correct. Let's talk about the correct approach to make all paragraph (`

`) elements bold. The correct syntax is `p {font-weight: bold}`. The `

` is a CSS selector. It selects all paragraph elements on the page. The `{font-weight: bold}` is a CSS declaration. It consists of two parts, separated by a colon. To the left of the colon, we have a property (`font-weight`). To the right, we see the value (`bold`). This specific declaration makes the text within the selected elements bold. Now you may be wondering why the other options are incorrect: 1. `p {font-weight bold}`: This is missing the colon (`:`) between the property and value. 2. `p: {font-weight: bold}`: The colon shouldn't be placed directly after the selector. 3. `p style='font-weight: bold'`: This isn't how you style elements in a CSS file. While this method could be used for inline-styling directly within HTML tags, it doesn't work in CSS sheets. Here's a practical example that applies the correct syntax: ```html

This paragraph will appear bold.

``` When viewed in a browser, the text within the `

` tags will be displayed in bold, due to the CSS styling declared in the `