Answers.Body: <p>I found the answer to this <a href="https://stackoverflow.com/a/27091873/5075214">on stackoverflow</a>. You can target different iBooks reading modes using these special CSS selectors:</p>
  
  <pre><code>:root[__ibooks_internal_theme*="Sepia"]
  :root[__ibooks_internal_theme*="Gray"]
  :root[__ibooks_internal_theme*="Night"]
  </code></pre>
  
  <p>Here's an example. I was using an <code>&lt;hr&gt;</code> below my chapter heading. I set the color to black, but in Night mode it disappears on the black background. This CSS changes the color to match the text when Night mode is active:</p>
  
  <pre><code>hr {
    border: 0;
    border-bottom: 1px solid black;
  }
  :root[__ibooks_internal_theme*="Night"] hr {
    border-bottom: 1px solid #b0b0b0;
  }
  </code></pre>
  
  <p>Used appropriately, this is super useful for getting your decorative elements to show up in Night/Gray modes or for retaining syntax highlighting in a programming book while in Night/Gray mode. However, as others have said on stackoverflow and at <a href="https://gist.github.com/adaptivegarage/aef95223fab9a39db45f" rel="nofollow noreferrer">the github page with sample code</a>, this is not a method that Apple has officially sanctioned, so remember not to abuse it or they could start blocking it.</p>
  
  <p>For reference, here are the default text and background colors for all four themes (obtained from screenshots of iBooks on my iPhone 6):</p>
  
  <pre><code>"White"
      color: #000000;
      background-color: #fbfbfb;
  "Sepia"
      color: #000000;
      background-color: #f8f1e3;
  "Gray"
      color: #c9caca;
      background-color: #5a5a5c;
  "Night"
      color: #b0b0b0;
      background-color: #121212;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-06T03:14:53.387Z
Answers.LastActivityDate: 2017-04-06T03:14:53.387Z
Answers.LastEditDate: 2017-05-23T12:37:39.963Z
Answers.UserDisplayName: blendenzo
Answers.Body: <p>While this is interesting, I have to wonder whether you are overthinking the problem. </p>
  
  <p>All that night mode does is invert the colors of the text and headlines. I can't imagine a case where the inverted colors would represent a problem (unless maybe you were using a third font color that was in between or you were coloring some background?) </p>
  
  <p>It's certainly important to test night mode. I also encountered an issue with some images I used in my heading. The images themselves had white background (or near white background) and looked less than ideal in night mode. Also, I discovered that it wasn't scaling to full width as I had thought. If you are using a transparent image, you'd want to make sure that there were enough contrasts with a darkened background. Or maybe specifying a background color would make sure that it is inverted in night mode. </p>
  
  <p>But I think readers expect that night mode might make a few things look funny. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-06T18:12:55.177Z
Answers.Text: I think you and I have a different way of looking at this, and I guess that's fine. To each his own, as they say. Personally, I wanted to provide a rich reading experience to my readers regardless of what mode they were reading in. It took me hours of crawling the web to find this solution (which works great), so I thought I would share it here to save others the trouble.  BTW, this method works great for swapping images depending on what mode the reader is using, so if you're using small file size decorative images (ornaments), you can provide alternate versions using `img { content:url(); }`
Answers.UserDisplayName: blendenzo
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-06T19:40:33.050Z
Answers.Text: Thanks. BTW, I never knew about the :root [] element {} selector syntax. Quite useful.
Answers.UserDisplayName: idiotprogrammer
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-06T10:27:35.120Z
Answers.LastActivityDate: 2017-04-06T10:27:35.120Z
Answers.UserDisplayName: idiotprogrammer
Body: <p>Is there a way to target Night mode (or Sepia or Gray mode for that matter) on iBooks with custom CSS? I have decorative elements in my chapter headings that I would like to match with the text colors in the various modes, but as it is they are disappearing against the black background.</p>
  
  <p>Since I'm trying to match those themes, what are the hex codes for the text and background colors? I know that the text in Night mode is not true white, so I'd like to match that if possible.</p>
  
Tags: <css><apple-books>
Title: Can you use CSS to target iOS night reading mode?
UserDisplayName: blendenzo
ThreadText: # Can you use CSS to target iOS night reading mode?
  
  (Asked by: username_0 on 2017-04-06)
  
  Is there a way to target Night mode (or Sepia or Gray mode for that matter) on iBooks with custom CSS? I have decorative elements in my chapter headings that I would like to match with the text colors in the various modes, but as it is they are disappearing against the black background.
  
  Since I'm trying to match those themes, what are the hex codes for the text and background colors? I know that the text in Night mode is not true white, so I'd like to match that if possible.
  
  **Tags:** css, apple-books
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2017-04-06. Score: 1 | Accepted answer
  
  I found the answer to this on stackoverflow. You can target different iBooks reading modes using these special CSS selectors:
  :root[__ibooks_internal_theme*="Sepia"]
  :root[__ibooks_internal_theme*="Gray"]
  :root[__ibooks_internal_theme*="Night"]
  
  Here's an example. I was using an  below my chapter heading. I set the color to black, but in Night mode it disappears on the black background. This CSS changes the color to match the text when Night mode is active:
  hr {
    border: 0;
    border-bottom: 1px solid black;
  }
  :root[__ibooks_internal_theme*="Night"] hr {
    border-bottom: 1px solid #b0b0b0;
  }
  
  Used appropriately, this is super useful for getting your decorative elements to show up in Night/Gray modes or for retaining syntax highlighting in a programming book while in Night/Gray mode. However, as others have said on stackoverflow and at the github page with sample code, this is not a method that Apple has officially sanctioned, so remember not to abuse it or they could start blocking it.
  For reference, here are the default text and background colors for all four themes (obtained from screenshots of iBooks on my iPhone 6):
  "White"
      color: #000000;
      background-color: #fbfbfb;
  "Sepia"
      color: #000000;
      background-color: #f8f1e3;
  "Gray"
      color: #c9caca;
      background-color: #5a5a5c;
  "Night"
      color: #b0b0b0;
      background-color: #121212;
  
  
  ---
  
  ### Answer by username_1 on 2017-04-06. Score: 0
  
  While this is interesting, I have to wonder whether you are overthinking the problem.
  
  All that night mode does is invert the colors of the text and headlines. I can't imagine a case where the inverted colors would represent a problem (unless maybe you were using a third font color that was in between or you were coloring some background?)
  
  It's certainly important to test night mode. I also encountered an issue with some images I used in my heading. The images themselves had white background (or near white background) and looked less than ideal in night mode. Also, I discovered that it wasn't scaling to full width as I had thought. If you are using a transparent image, you'd want to make sure that there were enough contrasts with a darkened background. Or maybe specifying a background color would make sure that it is inverted in night mode.
  
  But I think readers expect that night mode might make a few things look funny.
  
  > **Comments:**
  > **username_0**: I think you and I have a different way of looking at this, and I guess that's fine. To each his own, as they say. Personally, I wanted to provide a rich reading experience to my readers regardless of what mode they were reading in. It took me hours of crawling the web to find this solution (which works great), so I thought I would share it here to save others the trouble.  BTW, this method works great for swapping images depending on what mode the reader is using, so if you're using small file size decorative images (ornaments), you can provide alternate versions using `img { content:url(); }`  
  > **username_1**: Thanks. BTW, I never knew about the :root [] element {} selector syntax. Quite useful.  
  
  ---
  
  