16

I just wanna know how to do an if-statement in simple HTML. Like the [if IE6] thingy

I'd like to do something like this

[IF 5>6]

How's the syntax? I can't seem to find anything but [If!IE6] and things like that, is that even possible?

Thanks a lot

Edit: I want to compare just scalar numbers, cause I have a dynamically created HTML. For example [If 4 == 6]. I DON'T WANT TO CHECK IE VERSIONS.

Emil
  • 7,220
  • 17
  • 76
  • 135
Maggie Fortelli
  • 195
  • 1
  • 2
  • 10
  • 1
    Why did you write [if IE6] if you didn't want to compare IE versions? – punkrockbuddyholly Feb 24 '12 at 15:42
  • 3
    HTML is a markup language. Not a programming language. – cadrell0 Feb 24 '12 at 15:54
  • 6
    @MrMisterMan Because she mentions that this is the only kind of "If statement" she could find, even if it's not what she is looking for. To put it this way, if I said I was looking for a Porsche, but Google only turned up results for Volkswagen, that doesn't mean I wanted even more Volkswagen results. ;) – Nix Feb 24 '12 at 16:01

8 Answers8

19

Not in HTML. Consider using JavaScript instead.

Anthony Faull
  • 17,549
  • 5
  • 55
  • 73
  • 2
    No need for me to add my own answer - but the reason being that HTML is meant to mind markup only, not the logic of which markup to display - any type of logic that determines to show certain markup related to the display of (or hiding of) certain data is to be handled by either Javascript (client-side) or some embedded scripting or compiled server-side code (PHP or C#, for example, embedded within the HTML with special tags) – Mattygabe Feb 24 '12 at 16:05
9

No, it's not possible. What you have seen is conditional comments in IE, which only checks version numbers of IE, and is typically used to inject IE specific style sheets to fix CSS bugs for that particular browser.

devdigital
  • 34,151
  • 9
  • 98
  • 120
8

The <!--[if IE]> syntax only works in Internet Explorer. You'll need to use javascript or css to conditionally display html in other browsers.

jrummell
  • 42,637
  • 17
  • 112
  • 171
6

If you want to check for browser versions:

<!--[if lt IE 7]>
    <!-- For LOWER than IE7 -->
<![endif]-->

<!--[if IE 6]>
    <!-- For JUST IE6 -->
<![endif]-->

<!--[if gt IE 7]>
    <!-- For HIGHER than IE7 -->
<![endif]-->

Other than that, you cannot use if statements in HTML, as it is a markup language and not a programming language. You need to do it either server side or with Javascript.

Nix
  • 5,746
  • 4
  • 30
  • 51
2

I believe this is the page you are looking for http://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx

(I typed into google "IE conditional comments". It was the second result.)

punkrockbuddyholly
  • 9,675
  • 7
  • 36
  • 69
0

The closest thing I can think of is *NgIf or using ternary expressions in your html using angular - however, the assignment of the variables and the logic of that ngif statement would be done in javascript.

Jett
  • 781
  • 1
  • 14
  • 30
-1
[If lte IE 6]

This selects IE 5, 5.5 and 6. It's the closest to what you want.

CKKiller
  • 1,424
  • 1
  • 16
  • 20
-2

If you insert Javascript into your code, then you can easily use the if statement. To insert you have to use script and /script