HTML Black Code

This page contains HTML code for coloring an element black. Typically, you might be changing the color of text or the background color of that text or another element. But you can also use HTML color codes to change the color of an element's border.

Black Text

One way of setting black text is by using the HTML <p> tag along with the style attribute. This is called inline styles.

However, depending on how much text you need to color, you could apply the styles against a <div> tag (for all text within that element) or even the <body> tag (for all text on the page).

Source CodeResult

Black text

Here's the same thing, but this time using embedded styles.

Source CodeResult

Black text

You could also place the CSS code into a external style sheet.

Black Background Color

You can set the background color of an element to black by using the CSS background-color property or the background shorthand property. If you do this, you will need to ensure that any text (or foreground element) is not black, in order for it to be visible.

In this example, I've placed the text inside a <div> tag, set its background color to black, and set its text color to white.

Source CodeResult
White text, black background.

Black Border Color

When you use CSS to create a border around an element, you need to specify the border's color.

In this example, I've specified that the <div> should have a dotted border with a color of black.

Source CodeResult
Normal text, but with a border around the div element.

Black Color Codes

The above examples use black as the color value. I could just as easily used the hexadecimal or RGB color values and the result would've been the same.

Here are the various methods of specifying the color black in HTML.

Source CodeResult

Black text

Black text (hexadecimal #000000)

Black text (hexadecimal shorthand #000)

Black text (RGB value rgb(0,0,0))

Shades of Black

Here are some different shades of blacks & grays that can be used instead of just plain old "black".

Color Name Hex Code RGB Decimal Code RGB
Gainsboro DCDCDC 220,220,220
LightGrey D3D3D3 211,211,211
Silver C0C0C0 192,192,192
DarkGray A9A9A9 169,169,169
Gray 808080 128,128,128
DimGray 696969 105,105,105
LightSlateGray 778899 119,136,153
SlateGray 708090 112,128,144
DarkSlateGray 2F4F4F 47,79,79
Black 000000 0,0,0