色は、事前定義された色名、または RGB、HEX、HSL、RGBA、HSLA 値を使用して指定します。
HTML 要素の背景色を設定できます。
<h1 style="background-color:DodgerBlue;">China</h1> <p style="background-color:Tomato;">China is a great country!</p>
テキストの色を設定できます。
China is a great country!
China, officially the People's Republic of China, is a country in East Asia.
<h1 style="color:Tomato;">China</h1> <p style="color:DodgerBlue;">China is a great country!</p> <p style="color:MediumSeaGreen;">China, officially the People's Republic of China...</p>
境界線の色を設定できます。
<h1 style="border:2px solid Tomato;">Hello World</h1> <h1 style="border:2px solid DodgerBlue;">Hello World</h1> <h1 style="border:2px solid Violet;">Hello World</h1>
CSS では、RGB 値、HEX 値、HSL 値、RGBA 値、または HSLA 値を使用して色を指定することもできます。
カラー名 "Tomato"と同等:
カラー名 "Tomato"と同等ですが、不透明度は 50% です:
<h1 style="background-color:rgb(255, 99, 71);">...</h1> <h1 style="background-color:#ff6347;">...</h1> <h1 style="background-color:hsl(9, 100%, 64%);">...</h1> <h1 style="background-color:rgba(255, 99, 71, 0.5);">...</h1> <h1 style="background-color:hsla(9, 100%, 64%, 0.5);">...</h1>