diff --git a/CHANGELOG b/CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,6 @@
+- 0.6.0.0
+    * Add the operator (!?) for nicely setting conditional attributes
+
 - 0.5.2.0
     * Provide ToHtml and ToValue instances for Int32, Int64, Word, Word32,
       and Word64
diff --git a/blaze-markup.cabal b/blaze-markup.cabal
--- a/blaze-markup.cabal
+++ b/blaze-markup.cabal
@@ -1,5 +1,5 @@
 Name:         blaze-markup
-Version:      0.5.2.1
+Version:      0.6.0.0
 Homepage:     http://jaspervdj.be/blaze
 Bug-Reports:  http://github.com/jaspervdj/blaze-markup/issues
 License:      BSD3
diff --git a/src/Text/Blaze.hs b/src/Text/Blaze.hs
--- a/src/Text/Blaze.hs
+++ b/src/Text/Blaze.hs
@@ -60,6 +60,7 @@
 
       -- * Setting attributes
     , (!)
+    , (!?)
 
       -- * Modifiying Markup trees
     , contents
diff --git a/src/Text/Blaze/Internal.hs b/src/Text/Blaze/Internal.hs
--- a/src/Text/Blaze/Internal.hs
+++ b/src/Text/Blaze/Internal.hs
@@ -53,6 +53,7 @@
       -- * Setting attributes
     , Attributable
     , (!)
+    , (!?)
 
       -- * Modifying Markup elements
     , contents
@@ -411,6 +412,19 @@
 instance Attributable (MarkupM a -> MarkupM b) where
     h ! f = (! f) . h
     {-# INLINE (!) #-}
+
+-- | Shorthand for setting an attribute depending on a conditional.
+--
+-- Example:
+--
+-- > p !? (isBig, A.class "big") $ "Hello"
+--
+-- Gives the same result as:
+--
+-- > (if isBig then p ! A.class "big" else p) "Hello"
+--
+(!?) :: Attributable h => h -> (Bool, Attribute) -> h
+(!?) h (c, a) = if c then h ! a else h
 
 -- | Mark HTML as external data. External data can be:
 --
diff --git a/tests/Text/Blaze/Tests.hs b/tests/Text/Blaze/Tests.hs
--- a/tests/Text/Blaze/Tests.hs
+++ b/tests/Text/Blaze/Tests.hs
@@ -35,6 +35,7 @@
         , testProperty "well nested <>"            wellNestedBrackets
         , testProperty "unsafeByteString id"       unsafeByteStringId
 
+        , testCase     "conditional attributes"    conditionalAttributes
         , testCase     "contents 1"                contents1
         ]
 
@@ -113,6 +114,14 @@
         '<' -> if isOpen then False else wellNested True xs
         '>' -> if isOpen then wellNested False xs else False
         _   -> wellNested isOpen xs
+
+conditionalAttributes :: Assertion
+conditionalAttributes =
+    "<p class=\"foo\">Hello</p><p id=\"2nd\">World</p>" @=? renderUsingUtf8 html
+  where
+    html = do
+        p !? (4 > length [()], class_ "foo") $ "Hello"
+        p !? (null [()], class_ "bar") !? (True, id "2nd") $ "World"
 
 contents1 :: Assertion
 contents1 = "Hello World!" @=? renderUsingUtf8 (contents html)
