HTML 스타일(Styles)


HTML Styles

I am red

I am blue

Try it Yourself »

HTML 스타일링

모든 HTML 요소는 기본 스타일을 가진다 : (배경색 white, 텍스트 색 black,  텍스트 크기 12px ...)

HTML 요소의 기본 스타일의 변경은 style 속성으로 할 수 있다. 

다음의 예는 기본 배경색을 white 에서  lightgrey로 변경한다:

Example

<body style="background-color:lightgrey;">

<h1>This is a heading</h1>
<p>This is a paragraph.</p>

</body>
Try it Yourself »

Note   HTML 의 이전 버전에서 지원되던 bgcolor 속성은 HTML5 에서는 유효하지 않다.

HTML Style 속성

HTML style 속성은 다음과 같은 문법을 가진다.:

style="property1:value1; property2:value2;"

property1, property2 는 CSS 속성를,  value1, value2 는 CSS 값이다.

Note    CSS 에 대하여는 튜토리얼 후반부에서 다시 다룬다. 

HTML Text Color

color 성질(property)은 HTML 요소에 사용될 텍스트 색을 정의한다. :

Example

<h1 style="color:blue;">This is a heading</h1>
<p style="color:red;">This is a paragraph.</p>
Try it Yourself »

HTML Text Fonts

font-family 성질(property)은 HTML요소에 사용될 폰트를 정의한다.:

Example

<h1 style="font-family:verdana;">This is a heading</h1>
<p style="font-family:courier;">This is a paragraph.</p>
Try it Yourself »

Note   HTML 의 이전 버전에서 지원되던 <font>태그는 HTML5에서는 유효하지 않다.

HTML 텍스트 크기

font-size 성질은 HTML 요소에 사용될 텍스트 크기를 정의한다.:

Example

<h1 style="font-size:300%;">This is a heading</h1>
<p style="font-size:160%;">This is a paragraph.</p>
Try it Yourself »

HTML 텍스트 정렬

text-align 성질은 HTML 요소에 사용될 수평 정렬 방식을 정의한다.:

Example

<h1 style="text-align:center;">Centered Heading</h1>
<p>This is a paragraph.</p>
Try it Yourself »

Note HTML의 이전 버전에서 지원되던 <center>태그는 HTML5에서는 유효하지 않다.

Chapter Summary

  • HTML 요소를 스타일링하는데 style 속성을 사용
  • 배경색을 위해서는 background-color 사용
  • 텍스트 색을 위해서는 color 사용
  • 텍스트 폰트를 위해서는 font-family 사용
  • 텍스트 크기를 위해서는 Use font-size 사용
  • 텍스트 정렬을 위해서는 text-align 사용

Exercises!

Exercise 1 »  Exercise 2 »  Exercise 3 »  Exercise 4 »  Exercise 5 »  Exercise 6 »