aboutsummaryrefslogtreecommitdiff
path: root/files/tr/öğren/html/introduction_to_html/başlangıç/index.html
blob: f88ec96f22e272767cc9dfd3e56a3fc605c8e48c (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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
---
title: HTML ile Başlarken
slug: Öğren/HTML/Introduction_to_HTML/Başlangıç
translation_of: Learn/HTML/Introduction_to_HTML/Getting_started
---
<div>{{LearnSidebar}}</div>

<div>{{NextMenu("Learn/HTML/Introduction_to_HTML/The_head_metadata_in_HTML", "Learn/HTML/Introduction_to_HTML")}}</div>

<p class="summary">Senin başlaman için bu makalede HTML'in mutlak temellerini ele alıyoruz . Unsurları, nitelikleri ve duymuş olabileceğiniz diğer tüm önemli terimleri ve bunların dile uygun olanlarını tanımlıyoruz. Ayrıca bir HTML öğesinin nasıl yapılandırıldığını, tipik bir HTML sayfasının nasıl yapılandırıldığını ve diğer önemli temel dil özelliklerini açıklıyoruz. Bu arada, sizin ilginizi çekmek için  HTML ile biraz oynayacağız!</p>

<table class="learn-box standard-table">
 <tbody>
  <tr>
   <th scope="row">Ön Koşullar:</th>
   <td>
    <p>Temel bilgisayar bilgisi, <a href="https://developer.mozilla.org/en-US/Learn/Getting_started_with_the_web/Installing_basic_software">t</a>emel yazılım kurulumu ve dosyalarla çalışma için temel bilgi</p>
   </td>
  </tr>
  <tr>
   <th scope="row">Hedef:</th>
   <td>HTML dilini temel olarak tanımak ve birkaç HTML öğesi yazmak için biraz pratik yapmak.</td>
  </tr>
 </tbody>
</table>

<h2 id="HTML_nedir">HTML nedir?</h2>

<p>{{glossary("HTML")}} (Hypertext Markup Language) bir programlama dili değildir; Tarayıcınıza, ziyaret ettiğiniz web sayfalarının nasıl yapılandırılacağını anlatmak için kullanılan bir işaretleme dilidir. Web geliştiricisinin istediği kadar karmaşık veya basit olabilir. HTML, içeriğin farklı bölümlerini belli bir şekilde görünmesini veya göstermesini sağlamak için sarmak, sarmak veya işaretlemek için kullandığınız bir dizi {{sözlükçe ("Element", "elements")}} dizisinden oluşur. Ekteki {{glossary ("Tag", "tags")}}, web'deki başka bir sayfaya bağlantı kurmak, kelimeleri italikleştirmek vb. İçin köprü içeren bir içerik içerebilir. Örneğin, aşağıdaki içerik satırını kullanın:</p>

<pre>My cat is very grumpy</pre>

<p>Satırın tek başına durmasını istiyorsak, paragrafın içine paragraf ekleyerek paragraf ({{htmlelement("p")}}) olduğunu belirleyebiliriz </p>

<pre class="brush: html">&lt;p&gt;My cat is very grumpy&lt;/p&gt;</pre>

<div class="note">
<p><strong>Not</strong>: HTML'deki etiketler büyük / küçük harf duyarsızdır, yani büyük veya küçük harf olarak yazılabilirler. Örneğin, bir {{htmlelement ("title")}} etiketi &lt;title&gt;, &lt;TITLE&gt;, &lt;Title&gt;, &lt;TiTlE&gt;, vb. ile yazılabilir ve düzgün çalışacaktır. Bununla birlikte, en iyi uygulama tutarlılık, okunabilirlik ve diğer nedenlerle tüm etiketleri küçük harflerle yazmaktır.</p>
</div>

<h2 id="Bir_HTML_ögesinin_anatomisi">Bir HTML ögesinin anatomisi</h2>

<p>Paragraf elemanımızı biraz daha inceleyelim:</p>

<p><img alt="" src="https://mdn.mozillademos.org/files/9347/grumpy-cat-small.png" style="display: block; height: 255px; margin: 0px auto; width: 821px;"></p>

<p>Öğemizin ana bölümleri:</p>

<ol>
 <li>Açılış etiketi: Açma ve kapama açılı ayraçlara sarılmış elemanın adından (bu durumda, p) oluşur. Bu, elementin nerede başladığı ya da etkili olmaya başladığı - bu durumda paragrafın başlangıcı olduğu durumları belirtir.</li>
 <li>Kapama etiketi: Bu, açılış etiketinin aynısıdır, ancak öğe adından önce bir eğik çizgi içermesi dışında. Bu, öğenin nerede bittiğini belirtir - bu durumda paragrafın bittiği yerde. Bir kapanış etiketi eklememek yaygın bir başlangıç ​​hatasıdır ve garip sonuçlara yol açabilir.</li>
 <li>İçerik: Sadece metin içeren ögemizin içerik unsurudur.</li>
 <li>Öğe: Açılış etiketi artı kapanış etiketi ve içerik öğeye eşittir.</li>
</ol>

<h3 id="Aktif_öğrenme_ilk_HTML_ögenizi_oluşturun">Aktif öğrenme: ilk HTML ögenizi oluşturun</h3>

<p>Giriş alanını aşağıdaki satırı &lt;em&gt; ve &lt;/em&gt; etiketleriyle sararak düzenleyin (öğeyi açmadan önce &lt;em&gt; ve öğeyi kapatmak için &lt;/em&gt; koyun) - bu kodun satıra gerekir  italik vurgu vermelidir! Değişikliklerinizin güncellemesini <em>Çıktı</em> alanında canlı olarak görebilirsiniz.</p>

<p>Bir hata yaparsanız, <em>Sıfırla</em> düğmesini kullanarak her zaman sıfırlayabilirsiniz. Gerçekten sıkışırsanız, cevabı görmek için <em>Çözümü göste</em>r düğmesine basın.</p>

<div class="hidden">
<h6 id="Playable_code">Playable code</h6>

<pre class="brush: html">&lt;h2&gt;Live output&lt;/h2&gt;
&lt;div class="output" style="min-height: 50px;"&gt;
&lt;/div&gt;

&lt;h2&gt;Editable code&lt;/h2&gt;
&lt;p class="a11y-label"&gt;Press Esc to move focus away from the code area (Tab inserts a tab character).&lt;/p&gt;

&lt;textarea id="code" class="playable-code" style="min-height: 100px;width: 95%"&gt;
  This is my text.
&lt;/textarea&gt;

&lt;div class="controls"&gt;
  &lt;input id="reset" type="button" value="Reset" /&gt;
  &lt;input id="solution" type="button" value="Show solution" /&gt;
&lt;/div&gt;
</pre>

<pre class="brush: css">html {
  font-family: 'Open Sans Light',Helvetica,Arial,sans-serif;
}

h2 {
  font-size: 16px;
}

.a11y-label {
  margin: 0;
  text-align: right;
  font-size: 0.7rem;
  width: 98%;
}

body {
  margin: 10px;
  background: #f5f9fa;
}
</pre>

<pre class="brush: js">var textarea = document.getElementById('code');
var reset = document.getElementById('reset');
var solution = document.getElementById('solution');
var output = document.querySelector('.output');
var code = textarea.value;
var userEntry = textarea.value;

function updateCode() {
  output.innerHTML = textarea.value;
}

reset.addEventListener('click', function() {
  textarea.value = code;
  userEntry = textarea.value;
  solutionEntry = htmlSolution;
  solution.value = 'Show solution';
  updateCode();
});

solution.addEventListener('click', function() {
  if(solution.value === 'Show solution') {
    textarea.value = solutionEntry;
    solution.value = 'Hide solution';
  } else {
    textarea.value = userEntry;
    solution.value = 'Show solution';
  }
  updateCode();
});

var htmlSolution = '&lt;em&gt;This is my text.&lt;/em&gt;';
var solutionEntry = htmlSolution;

textarea.addEventListener('input', updateCode);
window.addEventListener('load', updateCode);

// stop tab key tabbing out of textarea and
// make it write a tab at the caret position instead

textarea.onkeydown = function(e){
  if (e.keyCode === 9) {
    e.preventDefault();
    insertAtCaret('\t');
  }

  if (e.keyCode === 27) {
    textarea.blur();
  }
};

function insertAtCaret(text) {
  var scrollPos = textarea.scrollTop;
  var caretPos = textarea.selectionStart;

  var front = (textarea.value).substring(0, caretPos);
  var back = (textarea.value).substring(textarea.selectionEnd, textarea.value.length);
  textarea.value = front + text + back;
  caretPos = caretPos + text.length;
  textarea.selectionStart = caretPos;
  textarea.selectionEnd = caretPos;
  textarea.focus();
  textarea.scrollTop = scrollPos;
}

// Update the saved userCode every time the user updates the text area code

textarea.onkeyup = function(){
  // We only want to save the state when the user code is being shown,
  // not the solution, so that solution is not saved over the user code
  if(solution.value === 'Show solution') {
    userEntry = textarea.value;
  } else {
    solutionEntry = textarea.value;
  }

  updateCode();
};</pre>
</div>

<p>{{ EmbedLiveSample('Playable_code', 700, 400, "", "", "hide-codepen-jsfiddle") }}</p>

<h3 id="İç_içe_geçmiş_ögeler">İç içe geçmiş ögeler</h3>

<p>Öğeleri başka öğelerin içine de yerleştirebilirsiniz - buna iç içe geçmiş öge denir. Kedimizin <strong>çok</strong> huysuz olduğunu söylemek istersek, "çok" kelimesini bir {{htmlelement ("strong")}} öğesinin içine koyabiliriz, bu kelimenin güçlü bir şekilde vurgulanması gerektiği anlamına gelir:</p>

<pre class="brush: html">&lt;p&gt;My cat is &lt;strong&gt;very&lt;/strong&gt; grumpy.&lt;/p&gt;</pre>

<p>Bununla birlikte, elemanlarınızın uygun şekilde   olduklarından emin olmanız gerekir: yukarıdaki örnekte önce p elementini, sonra güçlü elementi açtık, bu nedenle önce güçlü elementi, sonra p'yi kapatmalıyız. Aşağıdaki yanlış:</p>

<pre class="example-bad brush: html">&lt;p&gt;My cat is &lt;strong&gt;very grumpy.&lt;/p&gt;&lt;/strong&gt;</pre>

<p>Elemanlar doğru açılıp kapanmalıdır, bu yüzden açıkça birbirlerinin içinde veya dışındadırlar. Yukarıdaki gibi çakışırlarsa, web tarayıcınız ne söylemeye çalıştığınızı en iyi şekilde tahmin etmeye çalışır ve beklenmedik sonuçlar elde edebilirsiniz. Öyleyse yapmayın!</p>

<h3 id="Satır_içi_ögelere_karşı_blok">Satır içi ögelere karşı blok</h3>

<p>HTML'de bilmeniz gereken iki önemli öğe kategorisi vardır. Blok düzeyinde elemanlar ve satır içi elemanlar.</p>

<ul>
 <li>Blok düzeyindeki öğeler bir sayfada görünür bir blok oluşturur - ondan önce gelen içerikten yeni bir satırda görünürler ve ondan sonra gelen tüm içerikler de yeni bir satırda görünür. Blok düzeyinde öğeler, sayfadaki, örneğin paragrafları, listeleri, gezinme menülerini, altbilgileri vb. temsil eden yapısal öğeler olma eğilimindedir. Blok düzeyinde bir öğe, satır içi bir öğenin içine yerleştirilmez, ancak içine yerleştirilebilir başka bir blok seviyesi elemanı olabilirler.</li>
 <li>Satır içi öğeler, blok düzeyindeki öğeler arasında yer alan ve tüm paragrafları ve içerik gruplarını değil, belgenin içeriğinin yalnızca küçük bölümlerini çevreleyen öğelerdir. Satır içi öğe, belgede yeni bir satır görünmesine neden olmaz; normal olarak bir metin paragrafının içinde görünürler; örneğin, {{htmlelement ("a")}} elementi (köprü) veya {{htmlelement ("em")}} veya {{htmlelement ("strong")}} gibi vurgu öğeleri.</li>
</ul>

<p>Aşağıdaki örneği ele alalım:</p>

<pre class="brush: html">&lt;em&gt;first&lt;/em&gt;&lt;em&gt;second&lt;/em&gt;&lt;em&gt;third&lt;/em&gt;

&lt;p&gt;fourth&lt;/p&gt;&lt;p&gt;fifth&lt;/p&gt;&lt;p&gt;sixth&lt;/p&gt;
</pre>

<p>{{htmlelement ("em")}} bir satır içi öğedir, aşağıda görebileceğiniz gibi, ilk üç öğe, aralarında boşluk olmayan, aynı satırda oturur. Öte yandan, {{htmlelement ("p")}} blok düzeyinde bir öğedir, bu nedenle her öğe yeni bir satırda, her birinin üstünde ve altında boşluk olacak şekilde görünür (boşluk, tarayıcının paragraflara uyguladığı varsayılan CSS stilinden kaynaklanır ).</p>

<p>{{ EmbedLiveSample('Block_versus_inline_elements', 700, 200, "", "") }}</p>

<div class="note">
<p><strong>Not</strong>: HTML5, HTML5'deki öğe kategorilerini yeniden tanımladı: bkz. Öğe içeriği kategorileri. Bu tanımlar, daha öncekilerden daha doğru ve daha az belirsiz olsa da, "blok" ve "satır içi" den daha anlaşılması çok daha karmaşık olsa da, bu konu boyunca bunlara sadık kalacağız.</p>
</div>

<div class="note">
<p><strong>Not</strong>: Bu başlıkta kullanıldığı şekliyle "blok" ve "satır içi" terimleri aynı ada sahip CSS kutularının tipleriyle karıştırılmamalıdır. Varsayılan olarak ilişkilendirilirken, CSS görüntüleme türünü değiştirmek öğenin kategorisini değiştirmez ve hangi öğeleri içerebileceğini ve hangi öğeleri içerebileceğini etkilemez. HTML5'in bu terimleri bırakmasının nedenlerinden biri Bu oldukça yaygın karışıklığı önlemek.</p>
</div>

<div class="note">
<p><strong>Note</strong>: Blok ve satır içi öğelerin listelerini içeren faydalı referans sayfalarını bulabilirsiniz - bkz. Blok düzeyinde öğeler ve Satır içi öğeler.</p>
</div>

<h3 id="Boş_Ögeler">Boş Ögeler</h3>

<p>Tüm elemanlar yukarıdaki açılış etiketi, içerik ve kapanış etiketini takip etmez. Bazı öğeler yalnızca belgeye bir şey eklemek / yerleştirmek için genellikle kullanılan tek bir etiketten oluşur. Örneğin, {{htmlelement ("img")}} öğesi, bir görüntü dosyasını içinde bulunduğu konumda bir sayfaya yerleştirir:</p>

<pre class="brush: html">&lt;img src="https://raw.githubusercontent.com/mdn/beginner-html-site/gh-pages/images/firefox-icon.png"&gt;</pre>

<p>Bu, sayfanıza aşağıdakilerin çıktısını verir:</p>

<p>{{ EmbedLiveSample('Empty_elements', 700, 300, "", "", "hide-codepen-jsfiddle") }}</p>

<div class="note">
<p><strong>Not</strong>: Boş elemanlara bazen boş elemanlar da denir.</p>
</div>

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

<p>Öğelerin ayrıca şuna benzeyen nitelikleri de olabilir:</p>

<p><img alt='&amp;amp;amp;amp;amp;lt;p class="editor-note">My cat is very grumpy&amp;amp;amp;amp;amp;lt;/p>' src="https://mdn.mozillademos.org/files/9345/grumpy-cat-attribute-small.png" style="display: block; height: 156px; margin: 0px auto; width: 1287px;"></p>

<p>Öznitelikler, gerçek içerikte görünmesini istemediğiniz öğe hakkında ek bilgi içerir. Bu durumda, class niteliği, öğeye daha sonra stil bilgisi ve diğer şeylerle öğeyi hedeflemek için kullanılabilecek bir tanımlayıcı ad vermenizi sağlar.</p>

<p>Bir nitelik şunlara sahip olmalıdır:</p>

<ol>
 <li>Onunla eleman adı arasındaki boşluk (ya da eleman zaten bir ya da daha fazla özniteliğe sahipse, önceki öznitelik).</li>
 <li>Öznitelik adı, ardından eşit bir işaret.</li>
 <li>Açma ve kapama alıntı işaretlerinin etrafına sarılmış bir özellik değeri.</li>
</ol>

<h3 id="Aktif_öğrenme_Bir_elemana_nitelikler_ekleme">Aktif öğrenme: Bir elemana nitelikler ekleme</h3>

<p>Another example of an element is {{htmlelement("a")}} — this stands for "anchor" and will make the piece of text it wraps around into a hyperlink. This can take a number of attributes, but several are as follows:</p>

<ul>
 <li><code>href</code>: This attribute specifies as its value the web address that you want the link to point to; where the browser navigates to when the link is clicked. For example, <code>href="https://www.mozilla.org/"</code>.</li>
 <li><code>title</code>: The <code>title</code> attribute specifies extra information about the link, such as what the page is that you are linking to. For example, <code>title="The Mozilla homepage"</code>. This will appear as a tooltip when hovered over.</li>
 <li><code>target</code>: The <code>target</code> attribute specifies the browsing context which will be used to display the link. For example, <code>target="_blank"</code> will display the link in a new tab. If you want to display the link in the current tab just omit this attribute.</li>
</ul>

<p>Edit the line below in the <em>Input</em> area to turn it into a link to your favorite website. First, add the <code>&lt;a&gt;</code> element. Second, add the <code>href</code> attribute and the <code>title</code> attribute. Lastly, specify the <code>target</code> attribute to open the link in the new tab. You'll be able to see your changes update live in the <em>Output</em> area. You should see a link that when hovered over displays the <code>title</code> attribute's content, and when clicked navigates to the web address in the <code>href</code> element. Remember that you need to include a space between the element name, and each attribute.</p>

<p>If you make a mistake, you can always reset it using the <em>Reset</em> button. If you get really stuck, press the <em>Show solution</em> button to see the answer.</p>

<div class="hidden">
<h6 id="Playable_code2">Playable code2</h6>

<pre class="brush: html">&lt;h2&gt;Live output&lt;/h2&gt;

&lt;div class="output" style="min-height: 50px;"&gt;
&lt;/div&gt;

&lt;h2&gt;Editable code&lt;/h2&gt;
&lt;p class="a11y-label"&gt;Press Esc to move focus away from the code area (Tab inserts a tab character).&lt;/p&gt;

&lt;textarea id="code" class="input" style="min-height: 100px;width: 95%"&gt;
  &amp;lt;p&amp;gt;A link to my favorite website.&amp;lt;/p&amp;gt;
&lt;/textarea&gt;

&lt;div class="playable-buttons"&gt;
  &lt;input id="reset" type="button" value="Reset"&gt;
  &lt;input id="solution" type="button" value="Show solution"&gt;
&lt;/div&gt;</pre>

<pre class="brush: css">html {
  font-family: sans-serif;
}

h2 {
  font-size: 16px;
}

.a11y-label {
  margin: 0;
  text-align: right;
  font-size: 0.7rem;
  width: 98%;
}

body {
  margin: 10px;
  background: #f5f9fa;
}</pre>

<pre class="brush: js">var textarea = document.getElementById('code');
var reset = document.getElementById('reset');
var solution = document.getElementById('solution');
var output = document.querySelector('.output');
var code = textarea.value;
var userEntry = textarea.value;

function updateCode() {
  output.innerHTML = textarea.value;
}

reset.addEventListener('click', function() {
  textarea.value = code;
  userEntry = textarea.value;
  solutionEntry = htmlSolution;
  solution.value = 'Show solution';
  updateCode();
});

solution.addEventListener('click', function() {
  if(solution.value === 'Show solution') {
    textarea.value = solutionEntry;
    solution.value = 'Hide solution';
  } else {
    textarea.value = userEntry;
    solution.value = 'Show solution';
  }
  updateCode();
});

var htmlSolution = '&lt;p&gt;A link to my &lt;a href="https://www.mozilla.org/" title="The Mozilla homepage" target="_blank"&gt;favorite website&lt;/a&gt;.&lt;/p&gt;';
var solutionEntry = htmlSolution;

textarea.addEventListener('input', updateCode);
window.addEventListener('load', updateCode);

// stop tab key tabbing out of textarea and
// make it write a tab at the caret position instead

textarea.onkeydown = function(e){
  if (e.keyCode === 9) {
    e.preventDefault();
    insertAtCaret('\t');
  }

  if (e.keyCode === 27) {
    textarea.blur();
  }
};

function insertAtCaret(text) {
  var scrollPos = textarea.scrollTop;
  var caretPos = textarea.selectionStart;

  var front = (textarea.value).substring(0, caretPos);
  var back = (textarea.value).substring(textarea.selectionEnd, textarea.value.length);
  textarea.value = front + text + back;
  caretPos = caretPos + text.length;
  textarea.selectionStart = caretPos;
  textarea.selectionEnd = caretPos;
  textarea.focus();
  textarea.scrollTop = scrollPos;
}

// Update the saved userCode every time the user updates the text area code

textarea.onkeyup = function(){
  // We only want to save the state when the user code is being shown,
  // not the solution, so that solution is not saved over the user code
  if(solution.value === 'Show solution') {
    userEntry = textarea.value;
  } else {
    solutionEntry = textarea.value;
  }

  updateCode();
};</pre>
</div>

<p>{{ EmbedLiveSample('Playable_code2', 700, 400, "", "", "hide-codepen-jsfiddle") }}</p>

<h3 id="Boolean_attributes">Boolean attributes</h3>

<p>You'll sometimes see attributes written without values — this is perfectly allowed. These are called boolean attributes, and they can only have one value, which is generally the same as the attribute name. As an example, take the {{htmlattrxref("disabled", "input")}} attribute, which you can assign to form input elements if you want them to be disabled (greyed out) so the user can't enter any data in them.</p>

<pre>&lt;input type="text" disabled="disabled"&gt;</pre>

<p>As shorthand, it is perfectly allowable to write this as follows (we've also included a non-disabled form input element for reference, to give you more of an idea what is going on):</p>

<pre class="brush: html">&lt;!-- using the disabled attribute prevents the end user from entering text into the input box --&gt;
&lt;input type="text" disabled&gt;

&lt;!-- The user can enter text into the follow input, as it doesn't contain the disabled attribute --&gt;
&lt;input type="text"&gt;
</pre>

<p>The above HTML will give you a rendered output as follows:</p>

<p>{{ EmbedLiveSample('Boolean_attributes', 700, 100, "", "", "hide-codepen-jsfiddle") }}</p>

<h3 id="Omitting_quotes_around_attribute_values">Omitting quotes around attribute values</h3>

<p>When you look around the World Wide Web, you'll come across a number of strange markup styles, including attribute values without quotes. This is allowable in certain circumstances, but will break your markup in others. For example, if we revisit our link example from earlier, we could write a basic version with only the <code>href</code> attribute, like this:</p>

<pre class="brush: html">&lt;a href=https://www.mozilla.org/&gt;favorite website&lt;/a&gt;</pre>

<p>However, as soon as we add the <code>title</code> attribute in this style, things will go wrong:</p>

<pre class="example-bad brush: html">&lt;a href=https://www.mozilla.org/ title=The Mozilla homepage&gt;favorite website&lt;/a&gt;</pre>

<p>At this point the browser will misinterpret your markup, thinking that the <code>title</code> attribute is actually three attributes — a title attribute with the value "The", and two boolean attributes, <code>Mozilla</code> and <code>homepage</code>. This is obviously not what was intended, and will cause errors or unexpected behavior in the code, as seen in the live example below. Try hovering over the link to see what the title text is!</p>

<p>{{ EmbedLiveSample('Omitting_quotes_around_attribute_values', 700, 100, "", "", "hide-codepen-jsfiddle") }}</p>

<p>Our advice is to always include the attribute quotes — it avoids such problems, and results in more readable code too.</p>

<h3 id="Single_or_double_quotes">Single or double quotes?</h3>

<p>In this article you'll notice that the attributes are all wrapped in double quotes. You might however see single quotes in some people's HTML. This is purely a matter of style, and you can feel free to choose which one you prefer. Both the following lines are equivalent:</p>

<pre class="brush: html">&lt;a href="http://www.example.com"&gt;A link to my example.&lt;/a&gt;

&lt;a href='http://www.example.com'&gt;A link to my example.&lt;/a&gt;</pre>

<p>You should however make sure you don't mix them together. The following will go wrong!</p>

<pre class="example-bad brush: html">&lt;a href="http://www.example.com'&gt;A link to my example.&lt;/a&gt;</pre>

<p>If you've used one type of quote in your HTML, you can include the other type of quote inside your attribute values without causing any problems:</p>

<pre class="brush: html">&lt;a href="http://www.example.com" title="Isn't this fun?"&gt;A link to my example.&lt;/a&gt;</pre>

<p>However if you want to include a quote within the quotes where both the quotes are of the same type (single quote or double quote), you'll have to <a href="/en-US/docs/Learn/HTML/Introduction_to_HTML/Getting_started#Entity_references_Including_special_characters_in_HTML">use HTML entities</a> for the quotes. For example, this will break:</p>

<pre class="example-bad brush: html">&lt;a href='http://www.example.com' title='Isn't this fun?'&gt;A link to my example.&lt;/a&gt;</pre>

<p>So you need to do this:</p>

<pre class="brush: html">&lt;a href='http://www.example.com' title='Isn&amp;#39;t this fun?'&gt;A link to my example.&lt;/a&gt;</pre>

<h2 id="Anatomy_of_an_HTML_document">Anatomy of an HTML document</h2>

<p>That wraps up the basics of individual HTML elements, but they aren't very useful on their own. Now we'll look at how individual elements are combined to form an entire HTML page:</p>

<pre class="brush: html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;title&gt;My test page&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;p&gt;This is my page&lt;/p&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre>

<p>Here we have:</p>

<ol>
 <li><code>&lt;!DOCTYPE html&gt;</code>: The doctype. In the mists of time, when HTML was young (about 1991/2), doctypes were meant to act as links to a set of rules that the HTML page had to follow to be considered good HTML, which could mean automatic error checking and other useful things. They used to look something like this:

  <pre>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;</pre>
  However, these days no one really cares about them, and they are really just a historical artifact that needs to be included for everything to work right. <code>&lt;!DOCTYPE html&gt;</code> is the shortest string of characters that counts as a valid doctype; that's all you really need to know.</li>
 <li><code>&lt;html&gt;&lt;/html&gt;</code>: The {{htmlelement("html")}} element. This element wraps all the content on the entire page, and is sometimes known as the root element.</li>
 <li><code>&lt;head&gt;&lt;/head&gt;</code>: The {{htmlelement("head")}} element. This element acts as a container for all the stuff you want to include on the HTML page that <em>isn't</em> the content you are showing to your page's viewers. This includes things like keywords and a page description that you want to appear in search results, CSS to style our content, character set declarations, and more. You'll learn more about this in the next article in the series.</li>
 <li><code>&lt;meta charset="utf-8"&gt;</code>: This element sets the character set your document should use to UTF-8, which includes most characters from the vast majority of human written languages. Essentially it can now handle any textual content you might put on it. There is no reason not to set this, and it can help avoid some problems later.</li>
 <li><code>&lt;title&gt;&lt;/title&gt;</code>: The {{htmlelement("title")}} element. This sets the title of your page, which is the title that appears in the browser tab the page is loaded in, and is used to describe the page when you bookmark/favorite it.</li>
 <li><code>&lt;body&gt;&lt;/body&gt;</code>: The {{htmlelement("body")}} element. This contains <em>all</em> the content that you want to show to web users when they visit your page, whether that's text, images, videos, games, playable audio tracks, or whatever else.</li>
</ol>

<h3 id="Active_learning_Adding_some_features_to_an_HTML_document">Active learning: Adding some features to an HTML document</h3>

<p>If you want to experiment with writing some HTML on your local computer, you can:</p>

<ol>
 <li>Copy the HTML page example listed above.</li>
 <li>Create a new file in your text editor.</li>
 <li>Paste the code into the new text file.</li>
 <li>Save the file as <code>index.html</code>.</li>
</ol>

<div class="note">
<p><strong>Note</strong>: You can also find this basic HTML template on the <a href="https://github.com/mdn/learning-area/blob/master/html/introduction-to-html/getting-started/index.html">MDN Learning Area Github repo</a>.</p>
</div>

<p>You can now open this file in a web browser to see what the rendered code looks like, and then edit the code and refresh the browser to see what the result is. Initially it will look like this:</p>

<p><img alt="A simple HTML page that says This is my page" src="https://mdn.mozillademos.org/files/12279/template-screenshot.png" style="display: block; height: 365px; margin: 0px auto; width: 595px;">So in this exercise, you can edit the code locally on your computer, as outlined above, or you can edit it in the editable sample window below (the editable sample window represents just the contents of the {{htmlelement("body")}} element, in this case). We'd like you to have a go at implementing the following steps:</p>

<ul>
 <li>Just below the opening tag of the {{htmlelement("body")}} element, add a main title for the document. This should be wrapped inside an <code>&lt;h1&gt;</code> opening tag and <code>&lt;/h1&gt;</code> closing tag.</li>
 <li>Edit the paragraph content to include some text about something you are interested in.</li>
 <li>Make any important words stand out in bold by wrapping them inside a <code>&lt;strong&gt;</code> opening tag and <code>&lt;/strong&gt;</code> closing tag.</li>
 <li>Add a link to your paragraph, as <a href="/en-US/Learn/HTML/Introduction_to_HTML/Getting_started#Active_learning_Adding_attributes_to_an_element">explained earlier in the article</a>.</li>
 <li>Add an image to your document, below the paragraph, as <a href="/en-US/Learn/HTML/Introduction_to_HTML/Getting_started#Empty_elements">explained earlier in the article</a>. You'll get bonus points if you manage to link to a different image (either locally on your computer, or somewhere else on the web).</li>
</ul>

<p>If you make a mistake, you can always reset it using the <em>Reset</em> button. If you get really stuck, press the <em>Show solution</em> button to see the answer.</p>

<div class="hidden">
<h6 id="Playable_code3">Playable code3</h6>

<pre class="brush: html">&lt;h2&gt;Live output&lt;/h2&gt;

&lt;div class="output" style="min-height: 50px;"&gt;
&lt;/div&gt;

&lt;h2&gt;Editable code&lt;/h2&gt;
&lt;p class="a11y-label"&gt;Press Esc to move focus away from the code area (Tab inserts a tab character).&lt;/p&gt;

&lt;textarea id="code" class="input" style="min-height: 100px;width: 95%"&gt;
  &amp;lt;p&amp;gt;This is my page&amp;lt;/p&amp;gt;
&lt;/textarea&gt;

&lt;div class="playable-buttons"&gt;
  &lt;input id="reset" type="button" value="Reset"&gt;
  &lt;input id="solution" type="button" value="Show solution"&gt;
&lt;/div&gt;</pre>

<pre class="brush: css">html {
  font-family: sans-serif;
}

h1 {
 color: blue;
}

h2 {
  font-size: 16px;
}

.a11y-label {
  margin: 0;
  text-align: right;
  font-size: 0.7rem;
  width: 98%;
}

img {
  max-width: 100%;
}

body {
  margin: 10px;
  background: #f5f9fa;
}</pre>

<pre class="brush: js">var textarea = document.getElementById('code');
var reset = document.getElementById('reset');
var solution = document.getElementById('solution');
var output = document.querySelector('.output');
var code = textarea.value;
var userEntry = textarea.value;

function updateCode() {
  output.innerHTML = textarea.value;
}

reset.addEventListener('click', function() {
  textarea.value = code;
  userEntry = textarea.value;
  solutionEntry = htmlSolution;
  solution.value = 'Show solution';
  updateCode();
});

solution.addEventListener('click', function() {
  if(solution.value === 'Show solution') {
    textarea.value = solutionEntry;
    solution.value = 'Hide solution';
  } else {
    textarea.value = userEntry;
    solution.value = 'Show solution';
  }
  updateCode();
});

var htmlSolution = '&lt;h1&gt;Some music&lt;/h1&gt;&lt;p&gt;I really enjoy &lt;strong&gt;playing the drums&lt;/strong&gt;. One of my favorite drummers is Neal Peart, who\ plays in the band &lt;a href="https://en.wikipedia.org/wiki/Rush_%28band%29" title="Rush Wikipedia article"&gt;Rush&lt;/a&gt;.\ My favourite Rush album is currently &lt;a href="http://www.deezer.com/album/942295"&gt;Moving Pictures&lt;/a&gt;.&lt;/p&gt;\ &lt;img src="http://www.cygnus-x1.net/links/rush/images/albums/sectors/sector2-movingpictures-cover-s.jpg"&gt;';
var solutionEntry = htmlSolution;

textarea.addEventListener('input', updateCode);
window.addEventListener('load', updateCode);

// stop tab key tabbing out of textarea and
// make it write a tab at the caret position instead

textarea.onkeydown = function(e){
  if (e.keyCode === 9) {
    e.preventDefault();
    insertAtCaret('\t');
  }

  if (e.keyCode === 27) {
    textarea.blur();
  }
};

function insertAtCaret(text) {
  var scrollPos = textarea.scrollTop;
  var caretPos = textarea.selectionStart;

  var front = (textarea.value).substring(0, caretPos);
  var back = (textarea.value).substring(textarea.selectionEnd, textarea.value.length);
  textarea.value = front + text + back;
  caretPos = caretPos + text.length;
  textarea.selectionStart = caretPos;
  textarea.selectionEnd = caretPos;
  textarea.focus();
  textarea.scrollTop = scrollPos;
}

// Update the saved userCode every time the user updates the text area code

textarea.onkeyup = function(){
  // We only want to save the state when the user code is being shown,
  // not the solution, so that solution is not saved over the user code
  if(solution.value === 'Show solution') {
    userEntry = textarea.value;
  } else {
    solutionEntry = textarea.value;
  }

  updateCode();
};</pre>
</div>

<p>{{ EmbedLiveSample('Playable_code3', 700, 600, "", "", "hide-codepen-jsfiddle") }}</p>

<h3 id="Whitespace_in_HTML">Whitespace in HTML</h3>

<p>In the above examples you may have noticed that a lot of whitespace is included in the code listings — this is not necessary at all; the two following code snippets are equivalent:</p>

<pre class="brush: html">&lt;p&gt;Dogs are silly.&lt;/p&gt;

&lt;p&gt;Dogs        are
         silly.&lt;/p&gt;</pre>

<p>No matter how much whitespace you use (which can include space characters, but also line breaks), the HTML parser reduces each one down to a single space when rendering the code. So why use so much whitespace? The answer is readability — it is so much easier to understand what is going on in your code if you have it nicely formatted, and not just bunched up together in a big mess. In our HTML we've got each nested element indented by two spaces more than the one it is sitting inside. It is up to you what style of formatting you use (how many spaces for each level of indentation, for example), but you should consider formatting it.</p>

<h2 id="Entity_references_Including_special_characters_in_HTML">Entity references: Including special characters in HTML</h2>

<p>In HTML, the characters <code>&lt;</code>, <code>&gt;</code>,<code>"</code>,<code>'</code> and <code>&amp;</code> are special characters. They are parts of the HTML syntax itself, so how do you include one of these characters in your text, for example if you really want to use an ampersand or less-than sign, and not have it interpreted as code as some browsers may do?</p>

<p>We have to use character references — special codes that represent characters, and can be used in these exact circumstances. Each character reference is started with an ampersand (&amp;), and ended by a semicolon (;).</p>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Literal character</th>
   <th scope="col">Character reference equivalent</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>&lt;</td>
   <td>&amp;lt;</td>
  </tr>
  <tr>
   <td>&gt;</td>
   <td>&amp;gt;</td>
  </tr>
  <tr>
   <td>"</td>
   <td>&amp;quot;</td>
  </tr>
  <tr>
   <td>'</td>
   <td>&amp;apos;</td>
  </tr>
  <tr>
   <td>&amp;</td>
   <td>&amp;amp;</td>
  </tr>
 </tbody>
</table>

<p>The character reference equivalent could be easily remembered because the words it uses can be seen as less than for '&amp;lt;' , quotation for ' &amp;quot; ' and similarly for each. Do checkout the link to the wikipedia page to find more about entity reference. In the below example, you can see two paragraphs, which are talking about web technologies:</p>

<pre class="brush: html">&lt;p&gt;In HTML, you define a paragraph using the &lt;p&gt; element.&lt;/p&gt;

&lt;p&gt;In HTML, you define a paragraph using the &amp;lt;p&amp;gt; element.&lt;/p&gt;</pre>

<p>In the live output below, you can see that the first paragraph has gone wrong, because the browser thinks that the second instance of <code>&lt;p&gt;</code> is starting a new paragraph. The second paragraph looks fine, because we have replaced the angle brackets with character references.</p>

<p>{{ EmbedLiveSample('Entity_references_Including_special_characters_in_HTML', 700, 200, "", "", "hide-codepen-jsfiddle") }}</p>

<div class="note">
<p><strong>Note</strong>: A chart of all the available HTML character entity references can be found on Wikipedia: <a class="external text" href="http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references" rel="nofollow">List of XML and HTML character entity references</a>. Note that you don't need to use entity references for any other symbols, as modern browsers will handle the actual symbols just fine as long as your HTML's <a href="/en-US/docs/Learn/HTML/Introduction_to_HTML/The_head_metadata_in_HTML#Specifying_your_document's_character_encoding">character encoding is set to UTF-8</a>.</p>
</div>

<h2 id="HTML_comments">HTML comments</h2>

<p>In HTML, as with most programming languages, there is a mechanism available to write comments in the code — comments are ignored by the browser and invisible to the user, and their purpose is to allow you to include comments in the code to say how your code works, what the different parts of the code do, etc. This can be very useful if you return to a code base that you've not worked on for six months, and can't remember what you did — or if you hand your code over to someone else to work on.</p>

<p>To turn a section of content inside your HTML file into a comment, you need to wrap it in the special markers <code>&lt;!--</code> and <code>--&gt;</code>, for example:</p>

<pre class="brush: html">&lt;p&gt;I'm not inside a comment&lt;/p&gt;

&lt;!-- &lt;p&gt;I am!&lt;/p&gt; --&gt;</pre>

<p>As you can see below, the first paragraph appears in the live output, but the second one doesn't.</p>

<p>{{ EmbedLiveSample('HTML_comments', 700, 100, "", "", "hide-codepen-jsfiddle") }}</p>

<h2 id="Summary">Summary</h2>

<p>You've reached the end of the article — we hope you enjoyed your tour of the very basics of HTML! At this point you should understand what the language looks like, how it works at a basic level, and be able to write a few elements and attributes. This is a perfect place to be right now, as in subsequent articles in the module we will go into some of the things you have already looked at in a lot more detail, and introduce some new features of the language. Stay tuned!</p>

<div class="note">
<p><strong>Note</strong>: At this point, as you start to learn more about HTML, you might also want to start to explore the basics of Cascading Style Sheets, or <a href="/en-US/docs/Learn/CSS">CSS</a>. CSS is the language you use to style your web pages (e.g., changing the font or colors, or altering the page layout). HTML and CSS go very well together, as you'll soon discover.</p>
</div>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/HTML/Applying_color">Applying color to HTML elements using CSS</a></li>
</ul>

<div>{{NextMenu("Learn/HTML/Introduction_to_HTML/The_head_metadata_in_HTML", "Learn/HTML/Introduction_to_HTML")}}</div>

<div></div>

<h2 id="In_this_module">In this module</h2>

<ul>
 <li><a href="/en-US/docs/Learn/HTML/Introduction_to_HTML/Getting_started">Getting started with HTML</a></li>
 <li><a href="/en-US/docs/Learn/HTML/Introduction_to_HTML/The_head_metadata_in_HTML">What’s in the head? Metadata in HTML</a></li>
 <li><a href="/en-US/docs/Learn/HTML/Introduction_to_HTML/HTML_text_fundamentals">HTML text fundamentals</a></li>
 <li><a href="/en-US/docs/Learn/HTML/Introduction_to_HTML/Creating_hyperlinks">Creating hyperlinks</a></li>
 <li><a href="/en-US/docs/Learn/HTML/Introduction_to_HTML/Advanced_text_formatting">Advanced text formatting</a></li>
 <li><a href="/en-US/docs/Learn/HTML/Introduction_to_HTML/Document_and_website_structure">Document and website structure</a></li>
 <li><a href="/en-US/docs/Learn/HTML/Introduction_to_HTML/Debugging_HTML">Debugging HTML</a></li>
 <li><a href="/en-US/docs/Learn/HTML/Introduction_to_HTML/Marking_up_a_letter">Marking up a letter</a></li>
 <li><a href="/en-US/docs/Learn/HTML/Introduction_to_HTML/Structuring_a_page_of_content">Structuring a page of content</a></li>
</ul>