Slide 1

Slide 1 text

@mathias · #kodio_2014 Ten things I didn’t know about HTML

Slide 2

Slide 2 text

@mathias

Slide 3

Slide 3 text

Ten things I didn’t know about HTML @mathias · #kodio_2014

Slide 4

Slide 4 text

∞ things I didn’t know about HTML, CSS & JavaScript @mathias · #kodio_2014

Slide 5

Slide 5 text

Back to the ’90s kickin’ it old skool

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Background colors

Slide 8

Slide 8 text

Background colors

Slide 9

Slide 9 text

Background colors

Slide 10

Slide 10 text

Background colors

Slide 11

Slide 11 text

Background colors " #FF33FF

Slide 12

Slide 12 text

Background colors " #0F030F

Slide 13

Slide 13 text

Background colors " #00C000

Slide 14

Slide 14 text

Background colors " #000000

Slide 15

Slide 15 text

Background colors " #C00000

Slide 16

Slide 16 text

Background colors " #C0A000

Slide 17

Slide 17 text

Background colors " #000000

Slide 18

Slide 18 text

Background colors " #00D000

Slide 19

Slide 19 text

Background colors http://mths.be/bgcolor

Slide 20

Slide 20 text

Background colors http://mths.be/bgcolor

Slide 21

Slide 21 text

“Valid HTML” conformance criteria

Slide 22

Slide 22 text

Document Type Definition

Slide 23

Slide 23 text

DTD

Lorem ipsum.

Slide 24

Slide 24 text

DTD

Slide 25

Slide 25 text

DTD fail

Slide 26

Slide 26 text

DTD fail foo bar

Slide 27

Slide 27 text

DTD fail → can still be checked by a computer foo bar

Slide 28

Slide 28 text

Computer says no
not a quote

Slide 29

Slide 29 text

Computer says no → can only be checked by a human
not a quote

Slide 30

Slide 30 text

Take-away Don’t obsess about HTML validation. • not the whole story • validators have bugs, too Functionality trumps validation anyway.


Slide 31

Slide 31 text

Character references aka. “entities”

Slide 32

Slide 32 text

Character references

foo & bar

Slide 33

Slide 33 text

;

Slide 34

Slide 34 text

github:twbs/bootstrap#3057

Slide 35

Slide 35 text

github:twbs/bootstrap#3057

Slide 36

Slide 36 text

;

Slide 37

Slide 37 text

; PRETENDS TO BE OPTIONAL BREAKS STUFF WHEN OMITTED

Slide 38

Slide 38 text

Character references

foo & bar

Slide 39

Slide 39 text

Character references

foo &amp bar

Slide 40

Slide 40 text

Character references

foo&ampbar

Slide 41

Slide 41 text

Character references

foo & bar

http://mths.be/bdu

Slide 42

Slide 42 text

Character references

foo > bar

Slide 43

Slide 43 text

Character references

foo &gt bar

Slide 44

Slide 44 text

Character references

foo&gtbar

Slide 45

Slide 45 text

Character references

foo > bar

Slide 46

Slide 46 text

Character references

foo…bar

Slide 47

Slide 47 text

Character references

foo…bar

Slide 48

Slide 48 text

… is U+0085, right?

Slide 49

Slide 49 text

… is U+0085, right? ✘

Slide 50

Slide 50 text

Nope, not in HTML!

Slide 51

Slide 51 text

Nope, not in HTML!

Slide 52

Slide 52 text

…but it is in XHTML

Slide 53

Slide 53 text

Character references

Slide 54

Slide 54 text

Tags

Slide 55

Slide 55 text

Valid HTML 
 
 
 Foo
 
 
 …
 


Slide 56

Slide 56 text

Valid HTML 
 
 
 Foo
 
 
 …
 


Slide 57

Slide 57 text

Valid HTML 
 
 
 Huh?
 
 …


Slide 58

Slide 58 text

Valid HTML 
 
 
 Huh?
 
 …


Slide 59

Slide 59 text

Valid HTML 
 lolwut
 …


Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

^ n FTFY

Slide 63

Slide 63 text

Using CSS without HTML

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

CSS without HTML $ curl -i http://mathiasbynens.be/demo/css-without-html HTTP/1.1 200 OK Date: Wed, 03 Oct 2013 13:33:37 GMT Link: ;rel=stylesheet Content-Length: 0 Content-Type: text/html; charset=UTF-8 http://mths.be/bpe

Slide 67

Slide 67 text

CSS without HTML $ curl -i http://mathiasbynens.be/demo/css-without-html HTTP/1.1 200 OK Date: Wed, 03 Oct 2013 13:33:37 GMT Link: ;rel=stylesheet Content-Length: 0 Content-Type: text/html; charset=UTF-8 http://mths.be/bpe

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

Font family names

Slide 70

Slide 70 text

CSS html {
 font-family: 'Comic Sans MS';
 } “If there’s whitespace in the font family name, it must be quoted.”

Slide 71

Slide 71 text

CSS html {
 font-family: Comic Sans MS;
 } “If there’s whitespace in the font family name, it must be quoted.” http://mths.be/bft

Slide 72

Slide 72 text

CSS html {
 font-family: 456bereastreet;
 }

Slide 73

Slide 73 text

CSS html {
 font-family: 456bereastreet;
 }

Slide 74

Slide 74 text

CSS html {
 font-family: \34 56bereastreet;
 }

Slide 75

Slide 75 text

CSS html {
 font-family: \34 56bereastreet;
 }

Slide 76

Slide 76 text

CSS html {
 font-family: '456bereastreet';
 }

Slide 77

Slide 77 text

CSS http://mths.be/bjm

Slide 78

Slide 78 text

Attribute values

Slide 79

Slide 79 text

Attribute values a[href="foo"] { background: hotpink; }

Slide 80

Slide 80 text

Attribute values a[href=foo] { background: hotpink; }

Slide 81

Slide 81 text

Attribute values a[href=foo|bar] { background: hotpink; }

Slide 82

Slide 82 text

Attribute values a[href=foo|bar] { background: hotpink; }

Slide 83

Slide 83 text

Attribute values a[href="foo|bar"] { background: hotpink; } http://mths.be/bal

Slide 84

Slide 84 text

Attribute values http://mths.be/bjn

Slide 85

Slide 85 text

Handling user input

Slide 86

Slide 86 text

http://mths.be/bqv

Slide 87

Slide 87 text

http://mths.be/bqv

Slide 88

Slide 88 text

Characters in JS

Slide 89

Slide 89 text

JavaScript string length >> 'A'.length // U+0041 1 >> 'A' == '\u0041' true >> 'B'.length // U+0042 1 >> 'B' == '\u0042' true

Slide 90

Slide 90 text

String length ≠ char count >> 'A'.length // U+1D400 2 >> 'A' == '\uD835\uDC00' true >> 'B'.length // U+1D401 2 >> 'B' == '\uD835\uDC01' true http://mths.be/bed

Slide 91

Slide 91 text

Surrogate pairs // for non-BMP code points (> 0xFFFF) function getSurrogates(codePoint) { var high = Math.floor((codePoint - 0x10000) / 0x400) + 0xD800; var low = (codePoint - 0x10000) % 0x400 + 0xDC00; return [ high, low ]; } ! function getCodePoint(high, low) { var codePoint = (high - 0xD800) * 0x400 + low - 0xDC00 + 0x10000; return codePoint; } ! >> getSurrogates('A'); // U+1D400 [ 0xD835, 0xDC00 ] >> getCodePoint(0xD835, 0xDC00); 0x1D400 http://mths.be/bed

Slide 92

Slide 92 text

JS string character count function countSymbols(string) { return punycode.ucs2.decode(string).length; } ! >> countSymbols('A') // U+0041 1 >> countSymbols('A') // U+1D400 1 http://mths.be/punycode

Slide 93

Slide 93 text

JS variable names

Slide 94

Slide 94 text

Which is invalid? var H ̹̙̦̮͉̩̗̗ ͧ̇̏̊̾ Eͨ͆͒̆ͮ̃ ͏̷̮̣̫̤̣Cͯ̂͐ ͏̨̛͔̦̟͈̻O ̜͎͍͙͚̬̝̣ ̽ͮ͐͗̀ͤ̍̀ ͢ M̴̡̲̭͍͇̼̟̯̦ ̉̒͠ Ḛ̛̙̞̪̗ ͥ ͤͩ̾͑̔͐ ͅ Ṯ̴̷̷̗̼͍ ̿̿̓̽͐ H ̙̙ ̔̄ ͜ ; var "_ಠಠ_"; var ໦ϗ îਓƎ ℵೋീΔେ; var ʃː λ ˀπ ᐩᐨᐟᑉᐦᐸᐳ\u200C; var a; http://mths.be/ber

Slide 95

Slide 95 text

♥ JS var H ̹̙̦̮͉̩̗̗ ͧ̇̏̊̾ Eͨ͆͒̆ͮ̃ ͏̷̮̣̫̤̣Cͯ̂͐ ͏̨̛͔̦̟͈̻O ̜͎͍͙͚̬̝̣ ̽ͮ͐͗̀ͤ̍̀ ͢ M̴̡̲̭͍͇̼̟̯̦ ̉̒͠ Ḛ̛̙̞̪̗ ͥ ͤͩ̾͑̔͐ ͅ Ṯ̴̷̷̗̼͍ ̿̿̓̽͐ H ̙̙ ̔̄ ͜ ; // valid var !_ಠಠ_!; // valid var ໦ϗ îਓƎ ℵೋീΔେ; // valid var ʃː λ ˀπ ᐩᐨᐟᑉᐦᐸᐳ\u200C; // valid var a; // syntax error http://mths.be/ber

Slide 96

Slide 96 text

/^(?!(?:do|if|in|for|let|new|try|var|case|else| enum|eval|false|null|this|true|void|with|break| catch|class|const|super|throw|while|yield|delete| export|import|public|return|static|switch|typeof| default|extends|finally|package|private|continue| debugger|function|arguments|interface|protected| implements|instanceof)$)[$A-Z\_a-z\xaa\xb5\xba \xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0- \u02e4\u02ec\u02ee\u0370- \u0374\u0376\u0377\u037a-\u037d\u0386\u0388- \u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7- \u0481\u048a-\u0527\u0531-\u0556\u0559\u0561- \u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a

Slide 97

Slide 97 text

\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a- \u302f\u3099\u309a\ua620-\ua629\ua66f\ua674- \ua67d\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823- \ua827\ua880\ua881\ua8b4-\ua8c4\ua8d0- \ua8d9\ua8e0-\ua8f1\ua900-\ua909\ua926-\ua92d \ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0- \ua9d9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50- \uaa59\uaa7b\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe \uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3- \uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00- \ufe0f\ufe20-\ufe26\ufe33\ufe34\ufe4d-\ufe4f \uff10-\uff19\uff3f]*$/

Slide 98

Slide 98 text

JS variable names http://mths.be/bjo

Slide 99

Slide 99 text

Questions? @mathias