aboutsummaryrefslogtreecommitdiff
path: root/files/tr/web/css/font-size/index.html
blob: cacbec8ae554f0b6a3f866b9dab0c9d0611db012 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
---
title: font-size
slug: Web/CSS/font-size
tags:
  - CSS Fontlar
  - CSS özelliği
  - Referans
translation_of: Web/CSS/font-size
---
<div>{{CSSRef}}</div>

<p><span class="seoSummary"><strong><code>font-size</code></strong> <a href="/en-US/docs/Web/CSS">CSS</a>'in bir özelliği olup yazı boyutunu ayarlar.</span> This property is also used to compute the size of <code>em</code>, <code>ex</code>, and other relative {{cssxref("&lt;length&gt;")}} units.</p>

<div>{{EmbedInteractiveExample("pages/css/font-size.html")}}</div>



<h2 id="Syntax">Syntax</h2>

<pre class="brush:css no-line-numbers notranslate">/* &lt;absolute-size&gt; values */
font-size: xx-small;
font-size: x-small;
font-size: small;
font-size: medium;
font-size: large;
font-size: x-large;
font-size: xx-large;
font-size: xxx-large;

/* &lt;relative-size&gt; values */
font-size: smaller;
font-size: larger;

/* &lt;length&gt; values */
font-size: 12px;
font-size: 0.8em;

/* &lt;percentage&gt; values */
font-size: 80%;

/* Global values */
font-size: inherit;
font-size: initial;
font-size: unset;
</pre>

<p>The <code>font-size</code> property is specified in one of the following ways:</p>

<ul>
 <li>As one of the <a href="#absolute-size">absolute-size</a> or <a href="#relative-size">relative-size</a> keywords</li>
 <li>As a <code>&lt;length&gt;</code> or a <code>&lt;percentage&gt;</code>, relative to the parent element's font size</li>
</ul>

<h3 id="Değerler">Değerler</h3>

<dl>
 <dt id="absolute-size"><code>xx-small</code>, <code>x-small</code>, <code>small</code>, <code>medium</code>, <code>large</code>, <code>x-large</code>, <code>xx-large</code>, <code>xxx-large</code></dt>
 <dd>Absolute-size keywords, based on the user's default font size (which is <code>medium</code>).</dd>
 <dt id="relative-size"><code>larger</code>, <code>smaller</code></dt>
 <dd>Relative-size keywords. The font will be larger or smaller relative to the parent element's font size, roughly by the ratio used to separate the absolute-size keywords above.</dd>
 <dt id="&lt;length>">{{cssxref("&lt;length&gt;")}}</dt>
 <dd>
 <p>A positive {{cssxref("&lt;length&gt;")}} value. For most font-relative units (such as <code>em</code> and <code>ex</code>), the font size is relative to the parent element's font size.</p>

 <p>For font-relative units that are root-based (such as <code>rem</code>), the font size is relative to the size of the font used by the {{HTMLElement("html")}} (root) element.</p>
 </dd>
 <dt id="&lt;percentage>">{{cssxref("&lt;percentage&gt;")}}</dt>
 <dd>
 <p>A positive {{cssxref("&lt;percentage&gt;")}} value, relative to the parent element's font size.</p>
 </dd>
</dl>

<div class="note">
<p><strong>Note:</strong> To maximize accessibility, it is generally best to use values that are relative to the user's default font size.</p>
</div>

<h3 id="Formal_syntax">Formal syntax</h3>

<pre class="syntaxbox notranslate">{{csssyntax}}</pre>

<h2 id="Açıklama">Açıklama</h2>

<p>There are several ways to specify the font size, including with keywords or numerical values for pixels or ems. Choose the appropriate method based on the needs for the particular web page.</p>

<h3 id="Anahtar_Kelimeler">Anahtar Kelimeler</h3>

<p>Keywords are a good way to set the size of fonts on the web. By setting a keyword font size on the {{HTMLElement("body")}} element, you can set relative font-sizing everywhere else on the page, giving you the ability to easily scale the font up or down on the entire page accordingly.</p>

<h3 id="Pixels">Pixels</h3>

<p>Setting the font size in pixel values (<code>px</code>) is a good choice when you need pixel accuracy. A px value is static. This is an OS-independent and cross-browser way of literally telling the browsers to render the letters at exactly the number of pixels in height that you specified. The results may vary slightly across browsers, as they may use different algorithms to achieve a similar effect.</p>

<p>Font sizing settings can also be used in combination. For example, if a parent element is set to <code>16px</code> and its child element is set to <code>larger</code>, the child element displays larger than the parent element in the page.</p>

<div class="note"><strong>Note:</strong> Defining font sizes in <code>px</code> is <em><a href="https://en.wikipedia.org/wiki/Web_accessibility">not accessible</a></em>, because the user cannot change the font size in some browsers. For example, users with limited vision may wish to set the font size much larger than the size chosen by a web designer. Avoid using them for font sizes if you wish to create an inclusive design.</div>

<h3 id="Ems">Ems</h3>

<p>Another way of setting the font size is with <code>em</code> values. The size of an <code>em</code> value is dynamic. When defining the <code>font-size</code> property, an <code>em</code> is equal to the font size of the element on which the <code>em</code> is used. If you haven't set the font size anywhere on the page, then it is the browser default, which is often 16px. So, by default 1em = 16px, and 2em = 32px. If you set a <code>font-size</code> of 20px on the body element, then 1em = 20px and 2em = 40px. Note that the value 2 is essentially a multiplier of the current em size.</p>

<p>In order to calculate the em equivalent for any pixel value required, you can use this formula:</p>

<pre class="brush: plain notranslate">em = desired element pixel value / parent element font-size in pixels</pre>

<p>For example, suppose the font-size of the body of the page is set to 16px. If the font-size you want is 12px, then you should specify 0.75em (because 12/16 = 0.75). Similarly, if you want a font size of 10px, then specify 0.625em (10/16 = 0.625); for 22px, specify 1.375em (22/16).</p>

<p>The em is a very useful unit in CSS, since it automatically adapts its length relative to the font that the reader chooses to use.</p>

<p>One important fact to keep in mind: em values compound. Take the following HTML and CSS:</p>

<pre class="brush: css notranslate">html {
  font-size: 62.5%; /* font-size 1em = 10px on default browser settings */
}
span {
  font-size: 1.6em;
}</pre>

<pre class="brush: html notranslate">&lt;div&gt;
&lt;span&gt;Outer &lt;span&gt;inner&lt;/span&gt; outer&lt;/span&gt;
&lt;/div&gt;
</pre>

<p>The result is:</p>

<p>{{EmbedLiveSample("Ems", 400, 40)}}</p>

<p>Assuming that the browser's default <code>font-size</code> is 16px, the words “outer” would be rendered at 16px, but the word “inner” would be rendered at 25.6px. This is because the inner {{HTMLElement("span")}}'s <code>font-size</code> is 1.6em which is relative to its parent's <code>font-size</code>, which is in turn relative to its parent's <code>font-size</code>. This is often called <strong>compounding</strong>.</p>

<h3 id="Rems">Rems</h3>

<p><code>rem</code> values were invented in order to sidestep the compounding problem. <code>rem</code> values are relative to the root <code>html</code> element, not the parent element. In other words, it lets you specify a font size in a relative fashion without being affected by the size of the parent, thereby eliminating compounding.</p>

<p>The CSS below is nearly identical to the previous example. The only exception is that the unit has been changed to <code>rem</code>.</p>

<pre class="brush: css notranslate">html {
  font-size: 62.5%; /* font-size 1em = 10px on default browser settings */
}
span {
  font-size: 1.6rem;
}
</pre>

<p>Then we apply this CSS to the same HTML, which looks like this:</p>

<pre class="brush: html notranslate">&lt;span&gt;Outer &lt;span&gt;inner&lt;/span&gt; outer&lt;/span&gt;</pre>

<p>{{EmbedLiveSample("Rems", 400, 40)}}</p>

<p>In this example, the words “outer inner outer” are all displayed at 16px (assuming that the browser's <code>font-size</code> has been left at the default value of 10px).</p>

<h2 id="Örnekler">Örnekler</h2>

<h3 id="Örnek_1">Örnek 1</h3>

<pre class="brush: css notranslate">/* Paragraf boyutunu çok büyük yapar */
p { font-size: xx-large; }

/* &lt;h1&gt; etiketininin boyutunu kendisini kaplayan
   etikete göre 2.5 kat daha büyük yapar */
h1 { font-size: 250%; }

/* span etiketiyle çevrelenmiş yazının boyutu 16px yapar */
span { font-size: 16px; }
</pre>

<h3 id="Örnek_2">Örnek 2</h3>

<h4 id="CSS">CSS</h4>

<pre class="brush: css notranslate">.small {
  font-size: xx-small;
}
.larger {
  font-size: larger;
}
.point {
  font-size: 24pt;
}
.percent {
  font-size: 200%;
}
</pre>

<h4 id="HTML">HTML</h4>

<pre class="brush: html notranslate">&lt;h1 class="small"&gt;Small H1&lt;/h1&gt;
&lt;h1 class="larger"&gt;Larger H1&lt;/h1&gt;
&lt;h1 class="point"&gt;24 point H1&lt;/h1&gt;
&lt;h1 class="percent"&gt;200% H1&lt;/h1&gt;</pre>

<h4 id="Sonuç">Sonuç</h4>

<p>{{EmbedLiveSample('Example_2','600','200')}}</p>

<h2 id="Notlar">Notlar</h2>

<p><code>em</code> and <code>ex</code> units on the {{cssxref("font-size")}} property are relative to the parent element's font size (unlike all other properties, where they're relative to the font size on the element). This means <code>em</code> units and percentages do the same thing for {{cssxref("font-size")}}.</p>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('CSS4 Fonts', '#font-size-prop', 'font-size')}}</td>
   <td>{{Spec2('CSS4 Fonts')}}</td>
   <td>Adds <code>xxx-large</code> keyword.</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS3 Fonts', '#font-size-prop', 'font-size')}}</td>
   <td>{{Spec2('CSS3 Fonts')}}</td>
   <td>No change.</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS2.1', 'fonts.html#propdef-font-size', 'font-size')}}</td>
   <td>{{Spec2('CSS2.1')}}</td>
   <td>No change.</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS1', '#font-size', 'font-size')}}</td>
   <td>{{Spec2('CSS1')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<p>{{cssinfo}}</p>

<h2 id="Tarayıcı_uyumluluğu">Tarayıcı uyumluluğu</h2>

<div class="hidden">The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</div>

<p>{{Compat("css.properties.font-size")}}</p>