How can add extra info to the  tag? How can I add extra info like lang="ar" dir="rtl" to the &lt;html&gt; tag like the following? 

&lt;html{{ html_attributes }} lang="ar" dir="rtl"&gt;
You can use the following code, even though for those specific values, I would find a different way (e.g. setting the language for the shown page).

{% html_attributes.setAttribute("lang", "ar") %}
{% html_attributes.setAttribute("dir", "rtl") %}
&lt;html{{ html_attributes }}&gt;


Inside hook_preprocess_html(), since $variables['html_attributes'] is an Attribute object, so you can use Attribute::setAttribute(). 

$variables['html_attributes']-&gt;setAttribute("lang", "ar");
$variables['html_attributes']-&gt;setAttribute("dir", "rtl");