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 Code | Result |
---|---|
Black text |
Here's the same thing, but this time using embedded styles.
Source Code | Result |
---|---|
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 Code | Result |
---|---|
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 Code | Result |
---|---|
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 Code | Result |
---|---|
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".
|