Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Changed default tags to <mark> (from <strong>) in the highlight_phrase() method in text helper #1497

wants to merge 7 commits into from

I've changed the default tag for the highlight_phrase() method in the text helper from <strong> to <mark>.

The <mark> tag semantically represents highlighted text in HTML5. The spec details can be found here


Not sure it's appropriate to set it as default at this point, considering it's HTML 5.


I don't think because it is HTML5 it should stop it being used. It's semantically valid and the appropriate tag for this use case. Also browsers that don't understand the tag natively will still render the text inside it.

What do you think @philsturgeon @derekjones @pkriete @ericbarnes ?


If it doesn't exist in the HTML specifications prior to HTML 5, then it wouldn't be semantically valid for them. And while the text will be rendered - it won't be highlighted.


But then if we're going to wait for the HTML5 specification to be complete (and the section with the <mark> tag has been finalised) this pull request is going to be open until 2020.


It is an optional parameter, so everybody can change it to use the <mark> tag if they're developing an HTML5 application. It's just that changing the default might break it for existing apps that are not HTML5-ready.

Another thought however - I'm completely out of touch with the feature/html5 branch, but if there's some configuration setting or auto-detection on wether we use HTML 5 - it could be changed to depend on that in there.


True that users can currently set whichever tag they want in the function - but it's currently a <strong> which is now, with the advent of the <mark> tag, is the incorrect tag to use.

As for the auto-detection I strongly believe that is the wrong approach to go down


I'm not arguing on what is right or wrong, I'm just saying we have to maintain backwards-compatibility. :)


make it HTML5 :)
Most of the browsers already support it. We don't need to think about IE6 still, don't we? Besides, everybody can do:

mark { font-weight: bolder; }

My opinion is we should start converting all helpers that generate html to html5.


There're still users who simply can't or don't know how to move away from IE6. Backwards-compatibility won't hurt in this case IMHO.


I'm not talking about IE6 users, even Microsoft badly wants the IE6 problem to go away. This one isn't (directly) related to browsers' market share - it's about the already existing CodeIgniter applications. Correct me if I'm wrong, but to my knowledge no standard prior to HTML 5 has the <mark> tag, which means that it would break validation for those standards, while <strong> (I assume) is valid for HTML 5 as well.

I'm not against pushing for a wider HTML 5 adoption - I'm all for it, but it should happen in a less painful way.


EllisLab no longer supports IE6 at all, FYI. That's not a determining factor here, but I thought I'd mention it in case there was worry that we might demand that it work with dead browsers.

One solution would be to move CI's helpers to HTML 5, and maintain a separate repo of helpers for HTML 4 versions for those that need them.


In 3d8d4fb I've added a note on how to add styling for browsers which may not have default styling for <mark>


I'm apathetic to this pull request. The point of a 'default' value is that it is the most commonly used value. With the relative newness of HTML 5 I can't see that moving from < strong > to < mark > can be the most commonly used value.

I'm not against this request either as I can see it makes sense, however, this pull request has stimulated a discussion about HTML 5 not about whether the default needs changing, and I believe it would be better to have a proper discussion elsewhere and an agreed date as to when CI implements all 'common' elements of HTML 5, rather than it being a debate on each pull request of this type. Decide when HTML 5 becomes the CI standard and then implement all these pulls.

It wouldn't hurt either if the docs specifically highlighted when and where HTML 5 features had been used. (Note: I had to use < strong > tags here as < mark > tags are not implemented!)


I've updated this pull so it will auto merge and it now includes an upgrade note.

So what's the decision on introducing HTML5 into CI?


In the IRC people have suggested we have a $config['html5'] flag.

Personally I'm against this however if others think this is a better option then can I suggest we have it set to TRUE by default

function highlight_phrase($str, $phrase, $tag_open = '', $tag_close = '')
    if ($tag_open === '' && $tag_close === '')
        $tag_open = (config_item('HTML5')) ? '<mark>' : '<strong>';
        $tag_close = (config_item('HTML5')) ? '</mark>' : '</strong>';

    if ($str === '')
        return '';

    if ($phrase !== '')
        return preg_replace('/('.preg_quote($phrase, '/').')/i', $tag_open.'\\1'.$tag_close, $str);

    return $str;

@alexbilbie Where does this stand?


I think that the config option is great way to start introducing html5. Just make an option where you can choose between html5 and normal and make it default to normal.

That way future html5 change requests can make use of this config.

You will still be backwards compatible and yet give people the choice for html5


The current default values '<strong>' and '</strong>' do not have much sense. The author of the original text most probably would "occupy" these tags and when the system highlights a phrase surrounded with "strong" tag, it would not be visible. A wise developer would already need to add a specific class, for example '<strong class="highlight">'.

This is why a change of these default values would not be such a pain. Anyway, within the instruction for upgrade, those who want to use the "strong" tag might be advised to declare highlight_phrase() with the old defaults within MY_text_helper.php

Autodetection for HTML5 is a messy approach IMO.

Anyway, we are going to swallow the new class and file naming convention, so this change is not so big concern about backward compatibility. The <mark> tag really makes sense.


+1 for the initially proposed change.

<mark>This <strong>example</mark> works</strong> for me (Opera 12.16, IE 10, Firefox 22.0, Crome 28, Safari 5.1.7).

@narfbg narfbg referenced this pull request from a commit
@narfbg narfbg Change Text helper default tag from <strong> to <mark>
Supersedes PR #1497
@narfbg narfbg closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
2  system/helpers/text_helper.php
@@ -336,7 +336,7 @@ function highlight_code($str)
* @param string the closing tag to end the phrase with
* @return string
- function highlight_phrase($str, $phrase, $tag_open = '<strong>', $tag_close = '</strong>')
+ function highlight_phrase($str, $phrase, $tag_open = '<mark>', $tag_close = '</mark>')
if ($str === '')
2  user_guide_src/source/changelog.rst
@@ -78,6 +78,8 @@ Release Date: Not Released
- Added an optional paramater to ``delete_files()`` to enable it to skip deleting files such as .htaccess and index.html.
- ``read_file()`` is now a deprecated alias of ``file_get_contents()``.
- :doc:`Security Helper <helpers/security_helper>` function ``strip_image_tags()`` is now an alias for the same method in the :doc:`Security Library <libraries/security>`.
+ - :doc:`Text Helper <helpers/text_helper>` changes include:
+ - ``highlight_phrase()`` now returns a ``<mark>`` tag by default (changed from ``<strong>``).
- Database
13 user_guide_src/source/helpers/text_helper.rst
@@ -122,9 +122,18 @@ opening/closing HTML tags you would like the phrase wrapped in. Example
$string = "Here is a nice text string about nothing in particular.";
$string = highlight_phrase($string, "nice text", '<span style="color:#990000">', '</span>');
-The above text returns:
+The above text returns::
-Here is a nice text string about nothing in particular.
+ Here is a <span style="color:#990000">nice text</span> string about nothing in particular.
+Note, this function used to use the ``<strong>`` tag by default, as of CodeIgniter 3.0 the default
+tag is the HTML5 ``<mark>`` tag. Older browsers may not have built in styling for this tag so it is
+recommended you insert the following CSS into your stylesheet if you need to support these browsers::
+ mark {
+ background: #ff0;
+ color: #000;
+ }
7 user_guide_src/source/installation/upgrade_300.rst
@@ -83,6 +83,13 @@ Smiley helper js_insert_smiley()
:doc:`Smiley Helper <../helpers/smiley_helper>` function ``js_insert_smiley()`` has been deprecated
since CodeIgniter 1.7.2 and is now removed. You'll need to switch to ``smiley_js()`` instead.
+Text helper highlight_phrase()
+:doc:`Text Helper <../helpers/text_helper>` function ``highlight_phrase()`` now uses the HTML5 ``<mark>`` tag as the
+default tag. ``<mark>`` semantically describes highlighted text better than the ``<strong>`` tag which was used in
+older versions of CodeIgniter.
Security helper do_hash()
Something went wrong with that request. Please try again.