Answers.Body: <p>I found this to work quite well for adding Bootstraps "img-fluid" class automatically:</p>
  
  <pre><code>{{ entry.yourTextField|replace('&lt;img ', '&lt;img class="img-fluid" ')|raw }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-22T11:14:48.097Z
Answers.LastActivityDate: 2019-11-22T11:14:48.097Z
Answers.UserDisplayName: Adrian
Answers.Body: <p>There's a plugin that's supposed to do what you want: <a href="https://github.com/nilsenpaul/redactoraddattributes/" rel="nofollow">Redactor Add Attributes</a>, but unfortunately it doesn't work with Craft newer that 2.0 (which includes the completely refactored Redactor 10).</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-27T10:20:11.090Z
Answers.Text: Nope, sorry for that. If anyone has the time to make the necessary adjustments, I'd be more than happy to update the plugin.
Answers.UserDisplayName: Paul
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-27T09:48:23.433Z
Answers.LastActivityDate: 2015-05-27T10:14:39.253Z
Answers.LastEditDate: 2015-05-27T10:14:39.253Z
Answers.UserDisplayName: carlcs
Answers.Body: <p>I wrote a plugin called <a href="https://github.com/mmikkel/RetconHTML-Craft" rel="noreferrer">Retcon HTML</a> which will solve this nicely using PHP's <a href="http://php.net/manual/en/class.domdocument.php" rel="noreferrer">DOMDocument</a> class.</p>
  
  <p>You'll want to use the <code>attr</code> filter, which is documented <a href="https://github.com/mmikkel/RetconHTML-Craft/wiki/Attr" rel="noreferrer">here</a>:</p>
  
  <pre><code>{{ entry.richTextField | retconAttr( 'img', { 'class' : 'image fit' }) }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-19T09:11:31.393Z
Answers.Text: This is a really clean solution, thank you very much.
Answers.UserDisplayName: Masiorama
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-27T11:57:02.517Z
Answers.LastActivityDate: 2015-05-27T13:20:18.477Z
Answers.LastEditDate: 2015-05-27T13:20:18.477Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>How can I add a CSS class to all images inserted into a rich text field ?</p>
  
  <p>ie. so an image inserted has style= "image fit" added to the img selector</p>
  
Tags: <redactor>
Title: Adding class to images in rich text
ThreadText: # Adding class to images in rich text
  
  (Asked by: username_0 on 2015-05-27)
  
  How can I add a CSS class to all images inserted into a rich text field ?
  
  ie. so an image inserted has style= "image fit" added to the img selector
  
  **Tags:** redactor
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_4 on 2015-05-27. Score: 6 | Accepted answer
  
  I wrote a plugin called [Retcon HTML](https://github.com/mmikkel/RetconHTML-Craft) which will solve this nicely using PHP's [DOMDocument](http://php.net/manual/en/class.domdocument.php) class.
  
  You'll want to use the `attr` filter, which is documented [here](https://github.com/mmikkel/RetconHTML-Craft/wiki/Attr):
  
  ```
  {{ entry.richTextField | retconAttr( 'img', { 'class' : 'image fit' }) }}
  
  ```
  
  > **Comments:**
  > **username_5**: This is a really clean solution, thank you very much.  
  
  ---
  
  ### Answer by username_1 on 2019-11-22. Score: 3
  
  I found this to work quite well for adding Bootstraps "img-fluid" class automatically:
  
  ```
  {{ entry.yourTextField|replace('<img ', '<img class="img-fluid" ')|raw }}
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2015-05-27. Score: 1
  
  There's a plugin that's supposed to do what you want: [Redactor Add Attributes](https://github.com/nilsenpaul/redactoraddattributes/), but unfortunately it doesn't work with Craft newer that 2.0 (which includes the completely refactored Redactor 10).
  
  > **Comments:**
  > **username_3**: Nope, sorry for that. If anyone has the time to make the necessary adjustments, I'd be more than happy to update the plugin.  
  
  ---
  
  